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.

n 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.

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

思路:

给出n个点距离原点(0,0)的长度ri和在直角坐标系的横纵坐标,有两种方法课一下消灭这些点,1是从原点发出一条一定角度的射线,2是发出一条一定半径的弧线,在这些线上的点都会被消灭,问最少需要多少条线可以将全部点消灭

可以假设任何一个点都经过一条射线和一条弧线,那么所有的点都会成为射线和弧线的交点,题目则转化为需要最少多少条这些线可以将所有的这些点都覆盖,(以线为点,两种线的交点为边建图, 即是求最小嗲覆盖),可以将射线当做x集合,弧线当做y集合,给所有的射线和弧线分别用map标号,再跑一变二分图即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long ll; const int N = 22222;
int mat[N], vis[N], pos1[N], pos2[N], cnt, n;
vector<int> G[N]; bool Crosspath(int k)
{
int sx = G[k].size();
for(int i = 0; i < sx; ++i)
{
int j = G[k][i];
if(vis[j]) continue;
vis[j] = 1;
if(mat[j] == -1 || Crosspath(mat[j])) {
mat[j] = k;
return true;
}
}
return false;
} void hungary()
{
cnt = 0;
memset(mat, -1, sizeof mat);
for(int i = 1; i < n; ++i)
{
memset(vis, 0, sizeof vis);
if(Crosspath(i)) cnt++;
}
printf("%d\n", cnt);
} int main()
{
int _;
scanf("%d", &_);
while(_ --)
{
scanf("%d", &n);
map<int, int> mp1;
map<double, int> mp2;
mp1.clear();
mp2.clear();
for(int i = 0; i <= n; ++i) G[i].clear();
int num1 = 1, num2 = 1;
int a, b, c;
for(int i = 0; i < n; ++i) {
scanf("%d%d%d", &a, &b, &c);
double deg = c * 1.0 / b;
if(mp2[deg]) pos2[i] = mp2[deg];
else { pos2[i] = num2; mp2[deg] = num2++; } if(mp1[a]) pos1[i] = mp1[a];
else { pos1[i] = num1; mp1[a] = num1++; }
} for(int i = 0; i < n; ++i) {
G[ pos1[i] ].push_back(pos2[i]); }
// cout << num1 << endl;
n = num1;
// for(int i = 0; i < n; ++i) printf("%d ", pos1[i]);
// cout << endl;
// for(int i = 0; i < n; ++i) printf("%d ", pos2[i]);
hungary();
}
}

  

Tactical Multiple Defense System 二分图的更多相关文章

  1. UVALive 7008 Tactical Multiple Defense System

     Tactical Multiple Defense System Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld &a ...

  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. NEFU 84 五指山 (扩展欧几里得)

    五指山 Problem:84 Time Limit:1000ms Memory Limit:65536K Description 西游记中孙吾空大闹天宫,如来佛祖前来降伏他,说道:"我与你打 ...

  2. ios 宏定义 系统版本 判定

    当需要判断iOS系统版本的时候,相信很多人都会这么干: #define SystemVersion [[UIDevice currentDevice] systemVersion].floatValu ...

  3. Struts2自定义拦截器

    1. 需求 自定义拦截器实现,用户登录的访问控制. 2. 定义拦截器类 public class LoginInterceptor extends AbstractInterceptor { @Ove ...

  4. php命令行运行出现错误Call to undefined function curl_init()

    在windows命令行窗口下运行php命令,需要将php.exe所在的路径添加到Path环境变量,例如C:\wamp\bin\php\php5.4.3 启动Apache服务 在命令行中输入php te ...

  5. 关于Hibernate的关联映射

    何为关联映射 由于数据库的表与表之间存在的管理关系,可以分为一对一,一对多和多对多关联,一般情况下,在数据库设计中是通过表的外键来建立各种关系的,在Hibernate中则把数据库表与表之间的关系数据映 ...

  6. supersr--去除tableViewHeader的粘性

    这段代码能去除tableViewHeader的粘性 const static NSInteger kSectionHeaderHeight = 30; - (void)scrollViewDidScr ...

  7. ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(零) 前言

    前端时间听一个技术朋友说 LayIM 2.0 发布了,听到这个消息抓紧去官网看了一下.(http://layim.layui.com/)哎呀呀,还要购买授权[大家支持一下哦],果断买了企业版,喜欢钻研 ...

  8. 在MVC的项目中访问静态页面

    MVC在生成项目的时候会生成的WEB-INF底下.这个文件夹下面的文件是受保护的,都会走MVC的流程, 但是我希望在WebContent底下可以使用静态页面, 那么需要进入springmvc-serv ...

  9. 20145206邹京儒《Java程序设计》第一周学习总结

    20145206 <Java程序设计>第1周学习总结 教材学习内容总结 1.三大平台:Java SE.Java EE与Java ME.Java SE是各应用平台的基础,分为四个主要的部分: ...

  10. 【PHP小项目使用MVC架构】

    小项目名称是雇员管理系统. mvc是一种项目的开发模式,中文名称为模式视图控制器,是强制程序员将数据的输入.处理.输出分开的一种开发模式. 在这个小项目中,控制器使用service作为后缀名. 项目u ...