Codeforces Round #478 (Div. 2) D. Ghosts (Geometry)

D. Ghosts

write picture description here

portal

I glanced at D after passing the first three questions last night, oh...Geometric questions, slipped away, and went to prepare for the exam tomorrow (today).

In fact, this problem is actually very simple to operate as long as the idea is correct.
For the two starting coordinates, respectively ( X i , a X i + b ) and ( X j , a X j + b ) For the two of , they collide in motion if and only if the coordinates are the same, then we can list the following two formulas:

X i + t V X i = X j + t V X j
a X i + b + t V AND i = a X j + b + t V AND j

Solve the equation to get a t V X j a t V X i = t V AND j t V AND i
change simple have to arrive V AND i a V X i = V AND j a V X j
At the same time, we can also know that points with the same combined velocity direction will never collide,
so the final answer is the number of identical values ​​minus the number of corresponding vectors.

#include<cstdio>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

int n,a,b;

struct edge
{
    ll x,vx,vy;
}p[200005];

map<ll, ll >mp1;
map<pair<ll, ll> ,ll >mp2;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>a>>b;
    mp1.clear();
    mp2.clear();
    for(int i=0;i<n;i++)
    {
        cin>>p[i].x>>p[i].vx>>p[i].vy;
        ll x=p[i].x;
        ll vx=p[i].vx;
        ll vy=p[i].vy;
        mp1[vy-a*vx]++;
        mp2[make_pair(vx,vy)]++;
    }
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        ll x=p[i].x;
        ll vx=p[i].vx;
        ll vy=p[i].vy;
        sum+=mp1[vy-a*vx]-mp2[make_pair(vx,vy)];
    }
    cout<<sum<<endl;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325713875&siteId=291194637