cf D Bear and Floodlight

题意:有n个灯,每个灯有一个照亮的角度,现在从点(l,0)走到点(r,0),问这个人若一直被灯照着能最多走多远?

思路;状压dp,然后通过向量旋转求出点(dp[i[,0)与灯的坐标(p[j].x,p[j].y)形成的向量然后旋转角度p[j].a,得到旋转之后的在x坐标轴上的点,然后与dp[i|(1<<j)]比较更新,找出最大值,再与右端点比较。有个情况,在旋转向量时,可能不与坐标轴有交点,你就把dp[i|(1<<j)]=r;

 1 #include <cstdio>
 2 #include <cmath>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 const double pi=acos(-1.0);
 7
 8 int n;
 9 double l,r;
10 struct node
11 {
12     double x,y;
13     double a;
14 }p[30];
15 double dp[(1<<20)+10];
16
17 int main()
18 {
19      while(scanf("%d%lf%lf",&n,&l,&r)!=EOF)
20      {
21         for(int i=0; i<n; i++)
22         {
23             double aa;
24             scanf("%lf%lf%lf",&p[i].x,&p[i].y,&aa);
25             p[i].a=(double)(aa*1.0*pi/180);
26         }
27         for(int i=0; i<(1<<n); i++) dp[i]=l;
28         double ans=l;
29         for(int i=0; i<(1<<n); i++)
30         {
31             ans=max(ans,dp[i]);
32             for(int j=0; j<n; j++)
33             {
34                if((i&(1<<j))==0)
35                {
36                 double xx=dp[i]-p[j].x;
37                 double yy=-p[j].y;
38                 double x1=xx*cos(p[j].a)-yy*sin(p[j].a);
39                 double y1=xx*sin(p[j].a)+yy*cos(p[j].a);
40                 double sx=p[j].x+yy*(x1*1.0/y1);
41                 if(sx>r) sx=r;
42                 if(y1>=0)
43                 {
44                     dp[i|(1<<j)]=r;
45                     continue;
46                 }
47                 dp[i|(1<<j)]=max(dp[i|(1<<j)],sx);
48                }
49             }
50         }
51         printf("%.10lf\n",min(ans,r)-l);
52      }
53      return 0;
54 }

时间: 2024-08-09 12:08:11

cf D Bear and Floodlight的相关文章

Bear and Floodlight 状态压缩DP啊

Bear and Floodlight Time Limit: 4000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u [Submit]   [Go Back]   [Status] 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

Codeforces 385D - Bear and Floodlight

385D - Bear and Floodlight 题目大意:有一个人从( l , 0 ) 想走到 ( r , 0 ),有 n 盏路灯,位置为( xi , yi ),每盏路灯都有一个照射的角度ai 这个角度内的区间都被照亮,问你走之前任意调路灯的方向,这个人只能走路灯照亮的地方,问你他最多能往 r 方向走多少距离. 思路:本来我想的是才20盏灯直接枚举灯的顺序也不会超时的吧,复杂度才20!* 20,结果GG,T掉了,改成 状态压缩就过了,状态压缩也跑了2000+ms.dp[ i ],表示 i

CF 574E(Bear and Drawing-2*n点阵画树)

E. Bear and Drawing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it

cf B Bear and Strings

题意:给你一个字符串,然后找多少区间内含有“bear”,输出数目: 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 char str[5001]; 7 int pos[50001]; 8 9 int main() 10 { 11 while(scanf("%s",str)!=EOF) 12 { 13 int k=str

cf B. Bear and Compressing

B. Bear and Compressing 思路:字符串是什么样的有多种情况不定,但我们总是知道最后一个肯定是a,那么我们就可以反着推,看a是由那个序列变过来的,拿案例一的数据说,比如我们先看见ca,可以变成a,那a的上一个状态就是ca,由“ca”代替“a“,此时长度为2,还不够长,所以继续找,看“ca”中的“c”是哪个序列变过来的呢,这次我们找到了"cc“还有”ee“,同样代替,那“ca”的上一次状态就是“cca”或者“eea”此时找到,长度为n则答案加1,那这么一直寻找的过程就想到了DF

【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight

读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; const double PI=acos(-1.0); #define EPS 0.00000001 struct Point { double x,y; Point(

CodeForces 385 D.Bear and Floodlight 状压DP

枚举灯的所有可能状态(亮或者不亮)(1<<20)最多可能的情况有1048576种 dp[i]表示 i 状态时灯所能照射到的最远距离(i 的二进制中如果第j位为0,则表示第j个灯不亮,否则就是亮) 当i&(1<< j)时代表第i个状态灯j不亮,此时可由状态i转移到状态 i ^ ( 1 << j) 即dp[(i^(1<<j))]=max(dp[(i^(1<<j))],get(dp[i],j)) get是从dp[i]的位置开始第j个灯所能照亮的

Codeforces 385 D Bear and Floodlight

主题链接~~> 做题情绪:时候最后有点蛋疼了,处理点的坐标处理晕了.so~比赛完清醒了一下就AC了. 解题思路: 状态压缩DP ,仅仅有 20 个点.假设安排灯的时候仅仅有顺序不同的问题.全然能够用状态压缩去递推出来,仅仅是处理点的坐标的时候非常麻烦,理清思路就好了. 状态方程: dp [ S | (1 << i ) ]  = max( dp[ S |( 1 << i ) ] , dp[ S ] + W )  , 在状态 S 的情况下再加入 i 点(S 中先前不含 i 点),

dp题目列表

10271 - Chopsticks 10739 - String to Palindrome 10453 - Make Palindrome 10401 - Injured Queen Problem 825 - Walking on the Safe Side 10617 - Again Palindrome 10201 - Adventures in Moving - Part IV 11258 - String Partition 10564 - Paths through the Ho