主题链接~~>

做题情绪:时候最后有点蛋疼了,处理点的坐标处理晕了。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. Codeforces 145A-Lucky Conversion(规律)

    A. Lucky Conversion time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. UVA 10943 - How do you add? 递推

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. thinkphp中view页面中的volist标签转化为原生php分析(多去看源代码,你会发现不仅简单,方便你理解,还节约时间)

    thinkphp中view页面中的volist标签转化为原生php分析(多去看源代码,你会发现不仅简单,方便你理解,还节约时间) 一.总结 1.标签和原生php之间的关系:标签只是为了方便你使用,标签 ...

  4. DOCKER学习心得

    原文:DOCKER学习心得   前言: Docker的主要学习心得来源于<docker技术入门与实战> --2019.1.1->2019.1.5 la 着重从基础部分--实例分析-- ...

  5. Go语言实战_自己定义OrderedMap

    一. 自己定义OrderedMap 在Go语言中.字典类型的元素值的迭代顺序是不确定的.想要实现有固定顺序的Map就须要让自己定义的 OrderedMap 实现 sort.Interface 接口类型 ...

  6. LIVE555源代码研究之四:MediaServer (一)

    LIVE555源代码研究之四:MediaServer (一) 从本篇文章開始我们将从简单server程序作为突破点,深入研究LIVE555源代码. 从前面的文章我们知道.不论什么一个基于LIVE555 ...

  7. Swift 语言概览 -自己在Xcode6 动手写2-tableView

    import UIKit class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource { va ...

  8. [Angular Testing] Unit Testing -- Test component and service.

    Recommend to use angular-cli to generate component and service, so we can get testing templates. ng ...

  9. js课程 1-2 js概念

    js课程 1-2  js概念 一.总结 一句话总结:js标签元素也是js对象,有属性和方法,方法就是事件,属性就是标签属性,可以直接调用. 1.js中如何获取标签对象? getElement获取的是标 ...

  10. Android 软键盘监听事件

    Android软键盘的隐藏显示研究 Android是一个针对触摸屏专门设计的操作系统,当点击编辑框,系统自动为用户弹出软键盘,以便用户进行输入.     那么,弹出软键盘后必然会造成原有布局高度的减少 ...