码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 题目3305Surveillance(数学几何,三分)

时间:2015-02-23 15:32:46      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

Surveillance
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 274   Accepted: 92

Description

See.Eye.A, the world‘s biggest independent intelligence agency, is located in a very large underground building. Recently, due to the large amount of secret documents kept in different departments and due to some recent strange activities in the building, the managers of See.Eye.A have decided to install an advanced surveillance system to monitor all the activities within the building. But lack of budgets has forced them to accomplish this task with the minimum expenses possible.

To be more specific, the building is consisted of a set of long passages containing doors at their two ends. If two passages i and j share the same door, then one can enter passage i from j or exit from passage i to j through that door. It should be noted that there is exactly one simple path through passages and other doors between each pair of doors (i.e. the structure of the passages and the doors is like a tree). Also note that the doors are made circular and as a result, more than 2 passages can share the same door. In addition, to extend the building in future, a door may be a dead-end i.e. a door that does not connect its passage to another one.

The surveillance system consists of a set of cameras which should be installed in different parts of the building so that all parts of the building, including the doors and passages, can be monitored. After a thorough analysis, the engineers of See.Eye.A decided that a camera should only be installed on either above one of the doors or in the middle of a passage. Note that if a camera is installed above a door, then all the passages sharing that door, the doors in the other ends of these passages, and the door itself can be monitored. On the other hand, if a camera is installed in the middle of a passage, then passage itself, doors at its both ends and all the adjacent passages sharing doors with it can be monitored.

Now, they want to know the minimum number of cameras that can be installed to monitor all the doors and passages of the building, and they hired you to write a program to accomplish this task for them.

Input

The first line of input contains a single integer T, which is the number of test cases. Each test case starts with a line containing one integer 1 ≤ P ≤ 100 which is the number of passages in the building, followed by P lines each containing a pair of integers 0 ≤ AB ≤ 1,000,000,000 which are the unique IDs of the two doors at either side of each passage.

Output

For each test-case, your program should output the minimum number of needed cameras to monitor all the building, in a single line.

Sample Input

2
7
10 20
20 30
30 4
4 55
55 60
60 1
1 1024
9
10 30
20 30
30 40
40 50
50 60
50 70
40 80
80 90
80 100

Sample Output

3
3

Source

ac代码
#include<stdio.h>
#include<math.h>
#include<string.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define INF 1<<30
double pi=acos(-1.0);
struct s
{
	double x,y;
}b[550];
int n;
double fun(double a)
{
	double xmin=INF,ymin=INF,xmax=-INF,ymax=-INF;
	int i;
	for(i=0;i<n;i++)
	{
		double x=b[i].x*cos(a)-b[i].y*sin(a);
		double y=b[i].y*cos(a)+b[i].x*sin(a);
		xmin=min(x,xmin);
		ymin=min(y,ymin);
		xmax=max(x,xmax);
		ymax=max(y,ymax);
	}
	return max(ymax-ymin,xmax-xmin);
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		//int n;
		int i;
		double l,r,ans1,ans2;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			scanf("%lf%lf",&b[i].x,&b[i].y);
		}
		l=0;
		r=pi;
		while(r-l>1e-8)
		{
			double mid=(l+r)/2;
			double mmid=(mid+r)/2;
			ans1=fun(mid);
			ans2=fun(mmid);
			if(ans1<ans2)
				r=mmid;
			else
				l=mid;
		}
		printf("%.2lf\n",ans1*ans1);
	}
}


POJ 题目3305Surveillance(数学几何,三分)

标签:

原文地址:http://blog.csdn.net/yu_ch_sh/article/details/43915941

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!