【计算几何】【状压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(){}
Point(const double &X,const double &Y)
{
x=X;
y=Y;
}
}p[23];
typedef Point Vector;
Vector operator - (const Point &a,const Point &b)
{
return Vector(a.x-b.x,a.y-b.y);
}
Vector operator + (const Vector &a,const Vector &b)
{
return Vector(a.x+b.x,a.y+b.y);
}
double Cross(Vector a,Vector b)
{
return a.x*b.y-a.y*b.x;
}
Vector operator * (const double &K,const Vector &v)
{
return Vector(K*v.x,K*v.y);
}
double ang[23],f[1<<22];
int n,L,R;
Vector Rotate(Vector A,double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad),
A.x*sin(rad)+A.y*cos(rad));
}
Point GetIntersection(Point P,Vector v,Point Q,Vector w)
{
return P+(Cross(w,P-Q)/Cross(v,w))*v;
}
double calc(Point p,double rad,double x)
{
Vector v1=Rotate(Point(x,0)-p,rad);
if(v1.y>(-EPS))
return 2147483647.0;
return GetIntersection(p,v1,Point(0.0,0.0),Vector(1.0,0.0)).x;
}
int main()
{
//freopen("d.in","r",stdin);
scanf("%d%d%d",&n,&L,&R);
for(int i=1;i<=n;++i)
{
scanf("%lf%lf%lf",&p[i].x,&p[i].y,&ang[i]);
ang[i]=ang[i]/180.0*PI;
}
for(int i=0;i<(1<<n);++i)
f[i]=-2147483647.0;
f[0]=L;
for(int i=0;i<(1<<n);++i)
for(int j=1;j<=n;++j)
if(!((i>>(j-1))&1))
{
f[i|(1<<(j-1))]=max(f[i|(1<<(j-1))],calc(p[j],ang[j],f[i]));
if(f[i|(1<<(j-1))]-(double)R>(-EPS))
{
printf("%.9lf\n",(double)(R-L));
return 0;
}
}
printf("%.9lf\n",f[(1<<n)-1]-(double)L);
return 0;
}
【计算几何】【状压dp】Codeforces Round #226 (Div. 2) D. Bear and Floodlight的更多相关文章
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
/* 可以在筛选质数的同时,算出每组数据中能被各个质数整除的个数, 然后算出[0,s]的个数 [l,r] 的个数即为[0,r]的个数减去[0,l]个数. */ #include <stdio.h ...
- Codeforces Round #226 (Div. 2)A. Bear and Raspberry
/* 贪心的找到相邻两项差的最大值,再减去c,结果若是负数答案为0. */ 1 #include <stdio.h> #define maxn 105 int num[maxn]; int ...
- Codeforces Round #226 (Div. 2)B. Bear and Strings
/* 题意就是要找到包含“bear”的子串,计算出个数,需要注意的地方就是不要计算重复. */ 1 #include <stdio.h> #include <string.h> ...
- 状压dp Codeforces Beta Round #8 C
http://codeforces.com/contest/8/problem/C 题目大意:给你一个坐标系,给你一个人的目前的坐标(该坐标也是垃圾桶的坐标),再给你n个垃圾的坐标,这个人要捡完所有的 ...
- DP Codeforces Round #303 (Div. 2) C. Woodcutters
题目传送门 /* 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 问最多能砍到多少棵树 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 分情况讨论,若符合就取最 ...
- DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* 题意:选择a[k]然后a[k]-1和a[k]+1的全部删除,得到点数a[k],问最大点数 DP:状态转移方程:dp[i] = max (dp[i-1], dp[i-2] + (ll) ...
- 数学+DP Codeforces Round #304 (Div. 2) D. Soldier and Number Game
题目传送门 /* 题意:这题就是求b+1到a的因子个数和. 数学+DP:a[i]保存i的最小因子,dp[i] = dp[i/a[i]] +1;再来一个前缀和 */ /***************** ...
- 树形DP Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
题目传送门 /* 题意:求一个点为根节点,使得到其他所有点的距离最短,是有向边,反向的距离+1 树形DP:首先假设1为根节点,自下而上计算dp[1](根节点到其他点的距离),然后再从1开始,自上而下计 ...
- DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
随机推荐
- debounce 与 throttle 区别
原文地址:http://undefinedblog.com/debounce-and-throttle/ 二.什么是debounce 1. 定义 如果用手指一直按住一个弹簧,它将不会弹起直到你松 ...
- 在xml文件中引入带有@Configuration的Java类
在xml引入带有@Configuration的Java类,就是把这个带有@Configuration的Java类,当做一个普通的的类用<bean>标签引入: 核心代码如下: @Config ...
- Python爬虫学习笔记之爬取新浪微博
import requests from urllib.parse import urlencode from pyquery import PyQuery as pq from pymongo im ...
- CSS垂直居中小结
1.设置子元素: { ... position :absolute; margin:auto; top:; right:; bottom:; left:; } 2.设置子元素:(height必须是固定 ...
- 浅析 nth-child(n) 和 nth-of-type(n)
首先看一个例子 <div> <p>第一个段落</p> <p>第二个段落</p> </div> p:nth-child(2) { ...
- IDEA中如何使用svn
1.安装tortoiseSVN客户端时,这里一定要勾选上,否则使用时会报错. 2.安装好之后,想启用idea的SVN插件还需要在idea配置一下,file - setting 按钮打开设置界面 或者( ...
- Selenium tutorial/overview
copy from: http://www.jroller.com/selenium/ Selenium tutorial/overview 1. Selenium Introduction 2. S ...
- tcpip概述
网络协议通常分为不同层次进行开发,每一层分别负责不同的通信功能.一个类似TCPIP的协议簇是一组不同层次上的多个协议的组合.TCPIP通常被认为是一个四层协议系统,分为:应用层(telnet/FTP/ ...
- Centos7/RHEL 7 配置静态路由
如图: 业务地址:192.168.10.0/24 192.168.20.0/24管理地址:172.168.10.0/24 172.168.20.0/24 需求:每台主机配置两张网卡,分别连 ...
- Delphi New,Getmem,ReallocMem联系与区别
来自:http://www.cnblogs.com/jsrgren/archive/2011/10/31/2270353.html ---------------------------------- ...