• Codeforces 975D


    题意略。

    思路:我们来写一下公式:

    P1:(x1 + t * Vx1,y1 + t * Vy1)                P2:(x2 + t * Vx2,y2 + t * Vy2)

    x1 + t * Vx1 = x2 + t * Vx2

    y1 + t * Vy1 = y2 + t * Vy2

    a(x1 - x2) = t * (Vy2 - Vy1)

    x1 - x2 = t * (Vx2 - Vx1)

    a * (Vx2 - Vx1) = Vy2 - Vy1

    说明满足a * Vx2 - Vy2 = a * Vx1 - Vy1这个式子的就可以相交。

    这里要特殊考虑一下平行情况,我们要从所有贡献中减去平行的不合法情况,才能得到最终答案。注意,几个静止的点也是平行的。

    详见代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    
    LL n,a,b,vx,vy;
    map<LL,LL> mp;
    map<pair<LL,LL>,LL> mp1;
    
    int main(){
        scanf("%lld%lld%lld",&n,&a,&b);
        LL x;
        for(int i = 0;i < n;++i){
            scanf("%lld%lld%lld",&x,&vx,&vy);
            LL s = a * vx - vy;
            ++mp[s];
            mp1[make_pair(vx,vy)]++;
        }
        map<LL,LL>::iterator it;
        LL sum = 0;
        for(it = mp.begin();it != mp.end();++it){
            LL temp = it->second;
            LL contribute = temp * (temp - 1);
            sum += contribute;
        }
        map<pair<LL,LL>,LL>::iterator it1;
        for(it1 = mp1.begin();it1 != mp1.end();++it1){
            LL temp = it1->second;
            sum -= temp * (temp - 1);
        }
        printf("%lld
    ",sum);
        return 0;
    }
  • 相关阅读:
    11.2~11.8 每周总结
    11.30~11.6 每周总结
    架构之美 图书笔记 03
    每周总结 10.26-11.1
    每周总结 10.19-10.25
    每周总结 10.12-10.18
    [Tips] centos下docker服务开机自启动
    [Notes] Linux内网穿透
    [Tips] python 文件读写
    [Tips] python 文件读写
  • 原文地址:https://www.cnblogs.com/tiberius/p/9158807.html
Copyright © 2020-2023  润新知