Tactical Multiple Defense System

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

解题:最大匹配

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
unordered_map<int,int>imp;
unordered_map<double,int>dmp;
vector<int>g[maxn];
int a,b,R[maxn],Link[maxn];
double slop[maxn];
bool used[maxn];
bool match(int u){
for(int i = g[u].size()-; i >= ; --i){
if(used[g[u][i]]) continue;
used[g[u][i]] = true;
if(Link[g[u][i]] == - || match(Link[g[u][i]])){
Link[g[u][i]] = u;
return true;
}
}
return false;
}
int main(){
int kase,n,s,t;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
imp.clear();
dmp.clear();
for(int i = ; i < maxn; ++i) {g[i].clear();Link[i] = -;}
for(int i = a = b = ; i < n; ++i){
scanf("%d%d%d",R + i,&s,&t);
if(imp[R[i]] == ) imp[R[i]] = ++a;
slop[i] = atan2(t,s);
if(dmp[slop[i]] == ) dmp[slop[i]] = ++b;
g[imp[R[i]]].push_back(dmp[slop[i]]);
}
int ret = ;
for(int i = ; i <= a; ++i){
memset(used,false,sizeof used);
if(match(i)) ++ret;
}
printf("%d\n",ret);
}
return ;
}

最新文章

  1. 【vuejs小项目】一、脚手架搭建工作
  2. C#高级编程笔记 Day 8, 2016年9月 28日 (数组)
  3. nginx - ssl 配置 - globelsign ssl
  4. 【HDOJ】4982 Goffi and Squary Partition
  5. H5页开发规范/通用规范
  6. vs2010 正式版官方下载地址
  7. 页面类跳转Demo
  8. Python爬虫入门教程 50-100 Python3爬虫爬取VIP视频-Python爬虫6操作
  9. Skyline TerraExplorer -二次开发- 加载外部数据的各种连接串
  10. Django(九)admin相关知识
  11. [转]DBCP连接池的最简单应用(用于ORACLE数据库)
  12. hdoj:2053
  13. 如何查看SQL SERVER数据库当前连接数
  14. 组件式开发(Vue)
  15. 学习笔记之Model selection and evaluation
  16. String类、常量池、字符串比较
  17. 浮动布局float
  18. PDP context
  19. Lazarus的DBGrid中回车键的处理
  20. Max Factor(素数筛法)题解

热门文章

  1. bzoj 1755: [Usaco2005 qua]Bank Interest【模拟】
  2. bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场【bfs】
  3. 慕课网2-5 编程练习:通过jQuery通配符选择器进行文字变色
  4. Syntax error on token &quot;;&quot;, , expected 错误
  5. web界面bug-临时
  6. C语言小项目-火车票订票系统
  7. ACM_三角形的周长
  8. 因Window服务器自动更新并重启导致WebSphere服务停止服务故障一例
  9. 网上商城 Incorrect datetime value: &#39;&#39; for column &#39;ordertime&#39; at row 1
  10. centos源码编译安装nginx过程记录