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 ...
随机推荐
- Android 调用系统邮件,发送邮件到指定邮箱
在项目中,最后有一个联络我们,要求是点击号码还有邮箱地址能够发送邮件,这时候解决的方案其实有两种,一种是调用系统发邮件的软件,可以添加邮箱账号就可以发送邮件:第二种是使用javamail来发送邮件.在 ...
- jQuery笔记---选择器(二)
1.选择器练习: 1)查找UL中的元素的内容 格式:$(“ul li:XX”).text() XX:代表方法 比如:获取到第一元素,然后获取当中的值 $(“ul li:first”).text() 获 ...
- JSONP的使用示例(以及jquery版jsonp)超简单
前言: 平时工作中很少跨域,很少用到jsonp,但是几乎每次面试都会被问到这个问题.很崩溃. 菜鸟教程上的jsonp教程就很好.这里做个笔记,自己捋一遍. Jsonp(JSON with Paddin ...
- vue指令概览
原文 简书原文:https://www.jianshu.com/p/5fd47b7422fd 大纲 1.什么是vue指令 2.向指令中传入参数 3.指令中带入修饰符 4.指令的缩写 5.常见的vue指 ...
- FZU 2020 组合
组合数求模要用逆元,用到了扩展的欧几里得算法. #include<cstdio> int mod; typedef long long LL; void gcd(LL a,LL b,LL ...
- 10.12 android输入系统_InputStage理论
android应用程序对输入系统的处理分为多个阶段,我们把这些阶段称为InputStage 理论处理流程: (1)activity发给window,如果window不能处理,再由activity处理; ...
- ios根据字体大小设置
, , , , , , , , , , , }; //这么多字体,从大到小挨个尝试 ; UIFont *font; ; i < array_length; i++) { font = [font ...
- 关于浏览器不能执行JavaScrip问题的反思
今天在一篇博客(http://blog.csdn.net/u011043843/article/details/27959563)的时候,写着用于演示的Javascript代码不能再浏览器执行,非常是 ...
- POJ 题目2506Tiling(大数)
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8128 Accepted: 3941 Descriptio ...
- CSS文本阴影实例
原文 简书原文:https://www.jianshu.com/p/5abf2fa2f1b9 前言 以下的实例是我从<CSS实战>中看到的实例,当我看到这些实例的时候,发现平时不是很在意的 ...