标签:正方形 cti pac esc acm ati set dfs col
Problem UVA11853-Paintball
You are playing paintball on a 1000×1000 square ?eld. A number of your opponents are on the ?eld hiding behind trees at various positions. Each opponent can ?re a paintball a certain distance in any direction. Can you cross the ?eld without being hit by a paintball? Assume that the southwest corner of the ?eld is at (0,0) and the northwest corner at (0,1000).
The input contains several scenario. Each scenario consists of a line containing n ≤ 1000, the number of opponents. A line follows for each opponent, containing three real numbers: the (x,y) location of the opponent and its ?ring range. The opponent can hit you with a paintball if you ever pass within his ?ring range. You must enter the ?eld somewhere between the southwest and northwest corner and must leave somewhere between the southeast and northeast corners.
For each scenario, if you can complete the trip, output four real numbers with two digits after the decimal place, the coordinates at which you may enter and leave the ?eld, separated by spaces. If you can enter and leave at several places, give the most northerly. If there is no such pair of positions, print the line:‘IMPOSSIBLE’
0.00 1000.00 1000.00 800.00
题解:这个题思路比较奇特,有了对偶图的思路,这个题就基本上是个水题了。题目问的时能过去,反过来考虑,怎样不能过去。把正方形区域想象成湖,各个士兵形成的攻击范围看作一个个踏板,如果能够从上边界走到下边界,那么整个图就被分成了左右两部分,自然不能从左到右。并且这个条件时充要的,因此可以作为判据。之后就是如何找最北边。只看左边,如果某个踏板从上边界的踏板出发不能够到达,那该踏板就不对入口坐标造成影响,反过来,如果能到达,并且该踏板和左边界右交点,那么沿着它的上交点就能走回上边界,相当于左上角这一块被包围了,自然入口在下面,据此得到结论,只需要找出从上边界出发能到达的圆,计算出这些圆和左边界交点的最小值就是最北的入口,右边界同理。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 using namespace std; 7 const int maxn = 1000+5; 8 const double wide = 1000.0; 9 10 struct Point{ 11 double x,y,r; 12 }point[maxn]; 13 14 bool intersection(Point &a,Point &b){ 15 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)) <= a.r+b.r; 16 } 17 18 int n; 19 bool vis[maxn]; 20 double Left,Right; 21 22 void check_circle(int a){ 23 if(point[a].x-point[a].r < 0) Left = min(Left,point[a].y-sqrt(point[a].r*point[a].r-point[a].x*point[a].x)); 24 if(point[a].x+point[a].r > wide) Right = min(Right,point[a].y-sqrt(point[a].r*point[a].r-(wide-point[a].x)*(wide-point[a].x))); 25 } 26 27 bool dfs(int u){ 28 if(vis[u]) return false; 29 vis[u] = true; 30 if(point[u].y-point[u].r < 0) return true; 31 for(int v = 1;v <= n;v++){ 32 if(v==u || vis[v]) continue; 33 if(intersection(point[u],point[v]) && dfs(v)) return true; 34 } 35 check_circle(u); 36 return false; 37 } 38 39 int main() 40 { 41 //freopen("input.txt","r",stdin); 42 while(~scanf("%d",&n)){ 43 memset(vis,false,sizeof(vis)); 44 Left = Right = wide; 45 for(int i = 1;i <= n;i++){ 46 scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].r); 47 } 48 bool ok = true; 49 for(int i = 1;i <= n;i++){ 50 if(!vis[i] && point[i].y+point[i].r>=wide && dfs(i)){ 51 ok = false; 52 break; 53 } 54 } 55 if(ok) printf("%.2f %.2f %.2f %.2f\n",0.000,Left,wide,Right); 56 else printf("IMPOSSIBLE\n"); 57 } 58 return 0; 59 }
标签:正方形 cti pac esc acm ati set dfs col
原文地址:https://www.cnblogs.com/npugen/p/9520797.html