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 ;
}

UVALive 7008 Tactical Multiple Defense System的更多相关文章

  1. Tactical Multiple Defense System 二分图

    This problem is about a war game between two countries. To protect a base, your country built a defe ...

  2. Method and apparatus for providing total and partial store ordering for a memory in multi-processor system

    An improved memory model and implementation is disclosed. The memory model includes a Total Store Or ...

  3. PatentTips - Modified buddy system memory allocation

    BACKGROUND Memory allocation systems assign blocks of memory on request. A memory allocation system ...

  4. General-Purpose Operating System Protection Profile

    1 Protection Profile Introduction   This document defines the security functionality expected to be ...

  5. Uniform synchronization between multiple kernels running on single computer systems

    The present invention allocates resources in a multi-operating system computing system, thereby avoi ...

  6. UNIX标准及实现

    UNIX标准及实现 引言     在UNIX编程环境和C程序设计语言的标准化方面已经做了很多工作.虽然UNIX应用程序在不同的UNIX操作系统版本之间进行移植相当容易,但是20世纪80年代UNIX版本 ...

  7. .NET中RabbitMQ的使用

    概述 MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.RabbitMQ是一个在AMQP基础上完整的,可复用的企业消息系统.他遵循Mozilla Public ...

  8. POJ 3714 Raid

    Description After successive failures in the battles against the Union, the Empire retreated to its ...

  9. POJ3714 Raid

    Raid Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10625   Accepted: 3192 Description ...

随机推荐

  1. SQLAlchemy 反向生成 model 模型

    前言 Django 反向生成的 model 模型的命令 :  python manager.py inspectdb SQLAlchemy / Flask-SQLAlchemy则是: pip3 ins ...

  2. bzoj 2726: [SDOI2012]任务安排【cdq+斜率优化】

    cdq复健.jpg 首先列个n方递推,设sf是f的前缀和,st是t的前缀和: \[ f[i]=min(f[j]+s*(sf[n]-sf[j])+st[i]*(sf[i]-sf[j])) \] 然后移项 ...

  3. bzoj1202: [HNOI2005]狡猾的商人(并查集 差分约束)

    1202: [HNOI2005]狡猾的商人 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4127  Solved: 1981[Submit][Sta ...

  4. P4556 [Vani有约会]雨天的尾巴(线段树合并)

    传送门 一道线段树合并 首先不难看出树上差分 我们把每一次修改拆成四个,在\(u,v\)分别放上一个,在\(lca\)和\(fa[lca]\)各减去一个,那么只要统计一下子树里的总数即可 然而问题就在 ...

  5. Extjs grid禁用头部点击三角下拉菜单

    表格头部的三角在点击的时候禁止出现下拉菜单,给每一列添加属性menuDisabled:true xtype:'grid', enableColumnResize:false, columns:[ {t ...

  6. 例题 3-5 谜题 uva227 Puzzle

    A children’s puzzle that was popular years ago consisted of a × frame which contained small squares ...

  7. gitlab&Jenkins 详细介绍及其应用

    第1章 gitlab 1.1 系统环境 [root@jenkins ~]# cat  /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ...

  8. 图灵机(转自wiki)

    图灵机(英语:Turing machine),又称确定型图灵机,是英国数学家艾伦·图灵于1936年提出的一种抽象计算模型,其更抽象的意义为一种数学逻辑机,可以看作等价于任何有限逻辑数学过程的终极强大逻 ...

  9. Kafka~服务端几个常用的命令

    在Centos上安装和部署完成kafka之后,我们就可以向服务端推消息和消费它了,今天主要聊几个常用的命令,比建立topic,从broken显示所有topics列表,向broken发消息,从broke ...

  10. 通信协议------Http、TCP、UDP

    CP   HTTP   UDP: 都是通信协议,也就是通信时所遵守的规则,只有双方按照这个规则“说话”,对方才能理解或为之服务. TCP   HTTP   UDP三者的关系: TCP/IP是个协议组, ...