主题链接~~>

做题情绪:时候最后有点蛋疼了,处理点的坐标处理晕了。so~比赛完清醒了一下就AC了。

解题思路:

状态压缩DP ,仅仅有 20 个点。假设安排灯的时候仅仅有顺序不同的问题。全然能够用状态压缩去递推出来,仅仅是处理点的坐标的时候非常麻烦,理清思路就好了。

状态方程: dp [ S | (1 << i ) ]  = max( dp[ S |( 1 << i ) ] , dp[ S ] + W )  , 在状态 S 的情况下再加入 i 点(S 中先前不含 i 点),这样一直更新就 ok 了。

代码(有点挫了):

#include<iostream>
#include<sstream>
#include<map>
#include<cmath>
#include<fstream>
#include<queue>
#include<vector>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<stack>
#include<bitset>
#include<ctime>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std ;
#define INT __int64
const double INF = 99999999 ;
const double esp = 0.0000000001 ;
const double PI = acos(-1.0) ;
const int MY = 100000 + 5 ;
const int MX = (1<<20) + 5 ;
int n ;
double st ,sd ,dp[MX] ,ans ;
struct node
{
double x ,y ,z ;
}Tx[100] ;
double ct(double x ,int i)
{
double sx = Tx[i].x ,sy = Tx[i].y ;
double sa = Tx[i].z ; // 角度
double dis = sqrt((sx-x)*(sx-x)+sy*sy) ;
double a = sa*PI/(180*1.0) ,b ,L ,L1 ,c ;
if(sx == x) // 假设在正上方
{
if(a == PI/2.0) return ans ;
else
return sy * tan(a) ;
}
else if(x < sx) // 在右边
{
double ex = acos(sy/dis) ;
if(ex == a) // 正好
return L = dis*sin(a) ;
else if(a < ex) // 小于
{
b = asin(sy/dis) ; // 度数
L = dis*cos(b) ;
a = a + b ;
L = L - sy/tan(a) ;
}
else
{
c = acos(sy/dis) ;
L1 = dis*sin(c) ;
c = a - c ;
L = L1 + sy*tan(c) ;
}
return L ;
}
else if(x > sx)
{
c = acos(sy/dis) ;
if(c + a > PI/2.0)
return ans ;
else
{
a = a + c ;
L = sy*tan(a) ;
return L - dis*sin(c) ;
}
}
}
void DP()
{
for(int i = 0 ;i < (1<<n) ; ++i) // 初始化赋值
dp[i] = -1 ;
for(int i = 0 ;i < n ; ++i) // 初始化单个
dp[1<<i] = ct(st ,i) ;
for(int S = 0 ;S < (1<<n) ; ++S)
for(int i = 0 ;i < n ; ++i)
if(!(S&(1<<i)) && dp[S] != -1)
{
if(dp[S|(1<<i)] == -1)
dp[S|(1<<i)] = dp[S] + ct(st+dp[S] ,i) ;
else dp[S|(1<<i)] = max(dp[S|(1<<i)] ,dp[S] + ct(st+dp[S] ,i)) ;
}
double Max = 0 ;
for(int i = 0 ;i < (1<<n) ; ++i)
Max = max(Max ,dp[i]) ;
if(Max >= sd-st)
cout<<fixed<<setprecision(12)<<ans<<endl ;
else cout<<fixed<<setprecision(12)<<Max<<endl ;
}
int main()
{
while(~scanf("%d%lf%lf" ,&n ,&st ,&sd))
{
ans = sd - st ;
for(int i = 0 ;i < n ; ++i)
cin>>Tx[i].x>>Tx[i].y>>Tx[i].z ;
DP() ;
}
return 0 ;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

Codeforces 385 D Bear and Floodlight的更多相关文章

  1. CodeForces 385 D.Bear and Floodlight 状压DP

    枚举灯的所有可能状态(亮或者不亮)(1<<20)最多可能的情况有1048576种 dp[i]表示 i 状态时灯所能照射到的最远距离(i 的二进制中如果第j位为0,则表示第j个灯不亮,否则就 ...

  2. Codeforces 385 C Bear and Prime Numbers

    题目链接~~> 做题感悟:这题属于想法题,比赛时直接做的 D 题.可是处理坐标处理的头晕眼花的结果到最后也没AC. 解题思路: 由于查询的时候仅仅考虑素数,so~我们仅仅考虑素数就能够,这就须要 ...

  3. Codeforces 385D - Bear and Floodlight

    385D - Bear and Floodlight 题目大意:有一个人从( l , 0 ) 想走到 ( r , 0 ),有 n 盏路灯,位置为( xi , yi ),每盏路灯都有一个照射的角度ai ...

  4. Bear and Floodlight 状态压缩DP啊

    Bear and Floodlight Time Limit: 4000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u ...

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

    读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm& ...

  6. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. codeforces 385 c

    Description Recently, the bear started studying data structures and faced the following problem. You ...

  8. codeforces 680C C. Bear and Prime 100(数论)

    题目链接: C. Bear and Prime 100 time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. codeforces 680B B. Bear and Finding Criminals(水题)

    题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...

随机推荐

  1. 使用wepy开发微信小程序商城第三篇:购物车(布局篇)

    使用wepy开发微信小程序商城 第三篇:购物车(布局篇) 前两篇如下: 使用wepy开发微信小程序商城第一篇:项目初始化 使用wepy开发微信小程序商城第二篇:路由配置和页面结构 基于上两篇内容,开始 ...

  2. C#实现自己主动升级(附源代码)

           对于PC桌面应用程序而言,自己主动升级功能往往是不可缺少的. 而自己主动升级能够作为一个独立的C/S系统来开发,这样,就能够在不同的桌面应用中进行复用.本文将着重介绍OAUS的相关背景. ...

  3. $_SERVER['DOCUMENT_ROOT']

    $_SERVER['DOCUMENT_ROOT'] 一.总结 $_SERVER 是一个包含了诸如头信息(header).路径(path).以及脚本位置(script locations)等等信息的数组 ...

  4. 任哲<<μC/OS>>

    从第二章开始啦: 程序控制块(TCB)  重要概念  相当于对应程序块的学生证,学号,,, 上面的图是一个简单的程序控制块,还会有复杂的程序控制块,也许是嵌套的两级的: 链表就相当于老师手中的花名册, ...

  5. POJ 1511 Invitation Cards (ZOJ 2008) 使用优先队列的dijkstra

    传送门: http://poj.org/problem?id=1511 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1008 ...

  6. 21、根据(应用程序)虚拟驱动vivi的使用过程彻底分析摄像头驱动(有ioctrl分析)

    videobuf2-core.h中的vb2_buffer,记录了v4l2_buffer ,驱动可以对vb2_buffer的v4l2_buffer进行操控, vb2_buffer是v4l2框架层的代码, ...

  7. 10、V4L2摄像头获取单幅图片测试程序(MMAP模式)

    #include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h> ...

  8. ios 获取button所在的cell对象, 注意:ios7 =&lt; System Version &lt; ios8 获取cell对象的差别

    ios7 =< System Version< ios8 : ios7 =< System Version < ios8  下 button.superview.supervi ...

  9. linux ps命令,查看某进程cpu和内存占用率情况, linux ps命令,查看进程cpu和内存占用率排序。 不指定

    背景:有时需要单看某个进程的CPU及占用情况,有时需要看整体进程的一个占用情况.一. linux ps命令,查看某进程cpu和内存占用率情况[root@test vhost]# ps auxUSER  ...

  10. MySQL 监控-innotop

    innotop 编写者Balon Schwartz,<高性能MySQL>的作者之一. innotop的作用为实时地展示服务器正在发生的事情,监控innodb,监控多个MySQL实例,是一款 ...