标签:des style blog http color os io strong
Time Limit: 4000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
One day a bear lived on the Oxy axis. He was afraid of the dark, so he couldn‘t move at night along the plane points that aren‘t lit. One day the bear wanted to have a night walk from his house at point (l, 0) to his friend‘s house at point (r, 0), along the segment of length (r - l). Of course, if he wants to make this walk, he needs each point of the segment to be lit. That‘s why the bear called his friend (and yes, in the middle of the night) asking for a very delicate favor.
The Oxy axis contains n floodlights. Floodlight i is at point (xi, yi) and can light any angle of the plane as large as ai degree with vertex at point(xi, yi). The bear asked his friend to turn the floodlights so that he (the bear) could go as far away from his house as possible during the walking along the segment. His kind friend agreed to fulfill his request. And while he is at it, the bear wonders: what is the furthest he can go away from his house? Hep him and find this distance.
Consider that the plane has no obstacles and no other light sources besides the floodlights. The bear‘s friend cannot turn the floodlights during the bear‘s walk. Assume that after all the floodlights are turned in the correct direction, the bear goes for a walk and his friend goes to bed.
Input
The first line contains three space-separated integers n, l, r(1 ≤ n ≤ 20; - 105 ≤ l ≤ r ≤ 105). The i-th of the next n lines contain three space-separated integers xi, yi, ai( - 1000 ≤ xi ≤ 1000; 1 ≤ yi ≤ 1000; 1 ≤ ai ≤ 90) — the floodlights‘ description.
Note that two floodlights can be at the same point of the plane.
Output
Print a single real number — the answer to the problem. The answer will be considered correct if its relative or absolute error doesn‘t exceed 10 - 6.
Sample Input
2 3 5
3 1 45
5 1 45
2.000000000
1 0 1
1 1 30
0.732050808
1 0 1
1 1 45
1.000000000
1 0 2
0 2 90
2.000000000
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <math.h> 5 #include <algorithm> 6 using namespace std; 7 #define PI acos(-1) 8 #define eps 0.0000000001 9 struct point 10 { 11 double x,y,a; 12 }; 13 point p[50]; 14 double dp[1<<20]; 15 double dist(double x,double y,double x1,double y1) 16 { 17 return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)); 18 } 19 double solve(double s,int k) 20 { 21 double B=atan2(p[k].y,p[k].x-s),A=p[k].a*PI/180; 22 double C=max(0.0,PI-A-B),l=dist(s,0.0,p[k].x,p[k].y); 23 //cout<<A<<" "<<B<<" "<<C<<" "<<s+l*sin(A)/sin(C)<<endl; 24 return s+l*sin(A)/sin(C); 25 } 26 int main() 27 { 28 // freopen("in.txt","r",stdin); 29 int n,i,size,j,ok; 30 double l,r; 31 while(~scanf("%d%lf%lf",&n,&l,&r)) 32 { 33 ok=0; 34 for(i=0;i<n;i++) 35 { 36 scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].a); 37 if(p[i].y<0)p[i].y=-p[i].y; 38 } 39 size=1<<n; 40 for(i=0;i<size;i++)dp[i]=l; 41 for(i=0;!ok&&i<size;i++) 42 { 43 for(j=0;!ok&&j<n;j++) 44 { 45 if(i&(1<<j)) 46 continue; 47 dp[i|(1<<j)]=max(dp[i|(1<<j)],solve(dp[i],j)); 48 if(dp[i|(1<<j)]>=r)ok=1; 49 } 50 } 51 if(ok) 52 { 53 printf("%.9lf\n",r-l); 54 //cout<<"YES"<<endl; 55 } 56 else 57 printf("%.9lf\n",dp[(1<<n)-1]-l); 58 } 59 }
Bear and Floodlight 状态压缩DP啊,布布扣,bubuko.com
标签:des style blog http color os io strong
原文地址:http://www.cnblogs.com/ERKE/p/3903586.html