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 点),这样一直更新就 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的更多相关文章
- CodeForces 385 D.Bear and Floodlight 状压DP
枚举灯的所有可能状态(亮或者不亮)(1<<20)最多可能的情况有1048576种 dp[i]表示 i 状态时灯所能照射到的最远距离(i 的二进制中如果第j位为0,则表示第j个灯不亮,否则就 ...
- Codeforces 385 C Bear and Prime Numbers
题目链接~~> 做题感悟:这题属于想法题,比赛时直接做的 D 题.可是处理坐标处理的头晕眼花的结果到最后也没AC. 解题思路: 由于查询的时候仅仅考虑素数,so~我们仅仅考虑素数就能够,这就须要 ...
- Codeforces 385D - Bear and Floodlight
385D - Bear and Floodlight 题目大意:有一个人从( l , 0 ) 想走到 ( r , 0 ),有 n 盏路灯,位置为( xi , yi ),每盏路灯都有一个照射的角度ai ...
- Bear and Floodlight 状态压缩DP啊
Bear and Floodlight Time Limit: 4000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u ...
- 【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight
读懂题意发现是傻逼状压. 只要会向量旋转,以及直线求交点坐标就行了.(验证了我这俩板子都没毛病) 细节蛮多. #include<cstdio> #include<algorithm& ...
- 【32.89%】【codeforces 574D】Bear and Blocks
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- codeforces 385 c
Description Recently, the bear started studying data structures and faced the following problem. You ...
- 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 ...
- codeforces 680B B. Bear and Finding Criminals(水题)
题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...
随机推荐
- BUFSIZ
转http://www.judymax.com/archives/262 今天在看示例程序时冒出来一句args = emalloc(BUFSIZ); BUFSIZ是什么意思,查了一下才明白. 这是st ...
- SIP对话、事务详解
1,SIP对话的建立(图片来自于网络) SIP对话的建立包括invite request,response,ACK.其中response包含临时响应(1XX response)和最终响应(非1XX r ...
- 分类算法简介 分类: B10_计算机基础 2015-03-09 11:08 257人阅读 评论(0) 收藏
一.决策树 决策树是用于分类和预测的主要技术之一,决策树学习是以实例为基础的归纳学习算法,它着眼于从一组无次序.无规则的实例中 推理出以决策树表示的分类规则.构造决策树的目的是找出属性和类别间的关系, ...
- 搭建hbase-0.94.26集群环境 分类: B7_HBASE 2015-01-24 17:14 861人阅读 评论(0) 收藏
先安装hadoop1.2.1,见http://blog.csdn.net/jediael_lu/article/details/38926477 1.配置hbase-site.xml <prop ...
- (十二)RabbitMQ消息队列-性能测试
原文:(十二)RabbitMQ消息队列-性能测试 硬件配置 宿主机用的联想3850X6的服务器四颗E7-4850v3的处理器,DDR4内存,两块1.25TB的pcie固态.在宿主机上使用的事esxi5 ...
- php$get中文汉字参数乱码
最近写了个简单的页面,从浏览器中传入中文参数(test.php?name=测试),不论怎么设置utf-8的页面中都显示乱码,google了一把也查到了不少解决办法,但是问题的原因到底是什么呢?没有人深 ...
- centos7安装nginx的两种方法
第一种方式:通过yum安装 直接通过 yum install nginx 肯定是不行的,因为yum没有nginx,所以首先把 nginx 的源加入 yum 中 运行下面的命令: 1.将nginx放到y ...
- ios开发日期的NSDate,NSCalendar分类
#import <Foundation/Foundation.h> @interface NSDate (XMGExtension) /** */ // @property (nonato ...
- 摘录-Mybatis - Integer值为0的数据 return false
Mybatis在进行<if test="status != null and status != ''">判空操作时,如果status为0的时候,该判断条件的值为fal ...
- arcengine 要素类的复制
转自原文arcengine 要素类的复制 using System; using System.Collections.Generic; using System.Text; using ESRI.A ...