Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
This problem is about a war game between two countries. To protect a base, your country built a defense system called “Tactical Multiple Defense System” (TMD system in short). There are two weapons in the TMD system: Line gun and Circle gun. The Line gun can in one shot destroy all targets whose (two-dimensional) coordinates are on the same ray from the base, and the Circle gun can in one shot destroy all the targets with the same distance to the base. Note that in this game the coordinate of the base is (0, 0). The other country is going to attack the base of your country. They deploy missiles at some places according to their “National Missile Deployment Plan” (NMD plan). Your spy got the NMD plan and therefore you have the positions of all the missiles, which are the targets you need to destroy. As the commander of the TMD system, your mission is to determine how to destroy all the n missiles by Line gun and Circle gun with minimum number of total shots. The position Pi of a missile is given by three positive integers ri , si , ti which indicates the polar coordinate is (ri , arctan(ti/si)), i.e., the distance from the base to Pi is ri and the slope of the ray from the base and through Pi is ti/si . We shall say that Pi is on the ray of slope ti/si . To use the Line gun, you input two integer parameters t and s, press the fire button, and then it destroys all targets (missiles) on the ray of slope t/s. On the other hand, to use the Circle gun, you need to input a positive integer parameter r, and it can destroy all targets with distance r to the base, that is, it destroys targets exactly on the circle of radius r (but not the ones within the circle). Figure 8 illustrates some examples.
Technical Specification
• The number of missiles n is at most 20000 in each test case. It is possible that two missiles are at the same position.
• The three parameters (ri , si , ti) of each position are integers and satisfy 1000 < ri ≤ 6000 and 1 ≤ si , ti ≤ 10000. Input The first line contains an integer T indicating the number of test cases. There are at most 10 test cases. For each test case, the first line is the number of missiles n. Each of the next n lines contains the parameters ri , si , ti of one missile, and two consecutive integers are separated by a space.
Input
The first line contains an integer T indicating the number of test cases. There are at most 10 test cases. For each test case, the first line is the number of missiles n. Each of the next n lines contains the parameters ri , si , ti of one missile, and two consecutive integers are separated by a space.
Output
For each test case, output in one line the minimum number of shots to destroy all the missiles.
Sample Input
1
5
1010 1 2
1020 2 4
1030 3 6
1030 9 9
1030 9 1
Sample Output
2
解题:最大匹配
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 200100; 4 unordered_map<int,int>imp; 5 unordered_map<double,int>dmp; 6 vector<int>g[maxn]; 7 int a,b,R[maxn],Link[maxn]; 8 double slop[maxn]; 9 bool used[maxn]; 10 bool match(int u){ 11 for(int i = g[u].size()-1; i >= 0; --i){ 12 if(used[g[u][i]]) continue; 13 used[g[u][i]] = true; 14 if(Link[g[u][i]] == -1 || match(Link[g[u][i]])){ 15 Link[g[u][i]] = u; 16 return true; 17 } 18 } 19 return false; 20 } 21 int main(){ 22 int kase,n,s,t; 23 scanf("%d",&kase); 24 while(kase--){ 25 scanf("%d",&n); 26 imp.clear(); 27 dmp.clear(); 28 for(int i = 0; i < maxn; ++i) {g[i].clear();Link[i] = -1;} 29 for(int i = a = b = 0; i < n; ++i){ 30 scanf("%d%d%d",R + i,&s,&t); 31 if(imp[R[i]] == 0) imp[R[i]] = ++a; 32 slop[i] = atan2(t,s); 33 if(dmp[slop[i]] == 0) dmp[slop[i]] = ++b; 34 g[imp[R[i]]].push_back(dmp[slop[i]]); 35 } 36 int ret = 0; 37 for(int i = 1; i <= a; ++i){ 38 memset(used,false,sizeof used); 39 if(match(i)) ++ret; 40 } 41 printf("%d ",ret); 42 } 43 return 0; 44 }