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

解题:最大匹配

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = ;
  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()-; i >= ; --i){
  12. if(used[g[u][i]]) continue;
  13. used[g[u][i]] = true;
  14. if(Link[g[u][i]] == - || 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 = ; i < maxn; ++i) {g[i].clear();Link[i] = -;}
  29. for(int i = a = b = ; i < n; ++i){
  30. scanf("%d%d%d",R + i,&s,&t);
  31. if(imp[R[i]] == ) imp[R[i]] = ++a;
  32. slop[i] = atan2(t,s);
  33. if(dmp[slop[i]] == ) dmp[slop[i]] = ++b;
  34. g[imp[R[i]]].push_back(dmp[slop[i]]);
  35. }
  36. int ret = ;
  37. for(int i = ; i <= a; ++i){
  38. memset(used,false,sizeof used);
  39. if(match(i)) ++ret;
  40. }
  41. printf("%d\n",ret);
  42. }
  43. return ;
  44. }

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. Ubuntu12.04安装JDK(jdk-6u45-linux-x64.bin)(转载)

    首先下载jdk-6u45-linux-x64.bin, 如果是32bit系统下载相应的i386即可. 更改文件权限-> chmod a+x jdk-6u45-linux-x64.bin. 创建目 ...

  2. less新手入门(五)—— CssGuards、循环、合并

    九. CssGuards 警卫也可以应用于css选择器,这是一种语法糖,用于声明mixin,然后立即调用它. 例如,在1.5.0之前,您必须这样做 .my-optional-style() when ...

  3. 429c Leha and Function

    题目 解题报告 F(n, k)是在集合{1, 2, 3, ..., n}中所有的具有k个元素的子集中分别取最小值,相加后的期望. 例如:要求F(4, 2),根据定义有{1, 2}, {1, 3}, { ...

  4. magento 翻译使用实例

    在自定义的模块中若想要使用翻译,需在config.xml中加入如下配置 <config> <adminhtml> //后台 <translate> <modu ...

  5. document.write清除原有内容情况

    原博客: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta ...

  6. 两个input可能会用到的小方法

    1.一个普通的input元素,在不被 form包裹的时候,如何跳转或搜索 var oInput = document.getElementsByTagName('input')[0]; oInput. ...

  7. Android常见问题总结(二)

    1.布局文件LinearLayout线性布局添加内容报错. 解决方法: 线性布局LinearLayout中包裹的元素多余1个需要添加android:orientation属性. 2.android 的 ...

  8. CAD使用GetxDataLong读数据(网页版)

    主要用到函数说明: MxDrawEntity::GetxDataLong2 读取一个Long扩展数据,详细说明如下: 参数 说明 [in] LONG lItem 该值所在位置 [out, retval ...

  9. java_线程类的基本功能

    Thread类是实现了Runnable接口 其方法有: start()开始:开始线程 run()跑:线程内容 currentThread()现在的线程:返回当前线程 getName():获取线程名 s ...

  10. 【Redis】三、Redis安装及简单示例

    (四)Redis安装及使用   Redis的安装比较简单,仍然和大多数的Apache开源软件一样,只需要下载,解压,配置环境变量即可.具体安装过程参考:菜鸟教程Redis安装.   安装完成后,通过r ...