CF975D Ghosts

思路:

题意描述不清,应该问最多有多少次碰撞。

参考了http://codeforces.com/blog/entry/59202

实现:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef pair<ll, ll> pll;
 5 int main()
 6 {
 7     int n;
 8     ll a, b, x, p, q;
 9     while (cin >> n >> a >> b)
10     {
11         map<ll, map<pll, ll>> mp;
12         for (int i = 0; i < n; i++)
13         { 
14             cin >> x >> p >> q;
15             ll tmp = a * p - q;
16             pll k(p, q);
17             if (!mp.count(tmp)) { mp[tmp] = map<pll, ll>(); mp[tmp][k] = 0; }
18             mp[tmp][k]++;
19         }
20         ll ans = 0;
21         for (auto it: mp)
22         {
23             ll tot = 0;
24             for (auto itr: it.second) tot += itr.second;
25             for (auto itr: it.second) ans += itr.second * (tot - itr.second);
26         }
27         cout << ans << endl;
28     }
29     return 0;
30 }
原文地址:https://www.cnblogs.com/wangyiming/p/9035568.html