[Uva10641]Barisal Stadium(区间dp)
题意:按照顺时针给出操场的周边点,然后给出周围可以建设照明灯的位置,以及在该位置建设照明灯的代价,照明灯照射的范围与操场的边界相切,现在要求一个最小的花费,要求操场的所有边都被照射到。
解题关键:预处理每台灯能够覆盖到的范围,然后对环进行dp即可。对环进行dp的方法是枚举起点,覆盖所有点即可。
注意用叉积的方法处理灯能否照到某条边->某个点。
$dp[i][j]$表示从第$i$个点到第$j$个点之间的边都被照射到的最小代价,只要有某个等得照射范围有覆盖到$i$,$j$,就可以向外扩展。
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const double eps=1e-;
const int N=;
const int M=;
int n,m,dp[N];
bool flag[N];
struct Point{
double x,y;
Point(double x=,double y=) {
this->x=x;
this->y=y;
}
void read(){
scanf("%lf%lf",&x,&y);
}
}p[N],o; struct node{
int l,r,c;
}q[M]; bool judge(Point p0, Point p1, Point p2) {
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y)<-eps;//叉积判断是否能被照到
} node tra(Point t, int c){
node ans;
ans.c=c;
memset(flag,,sizeof flag);
for(int i=;i<n;i++) if(judge(t,p[i],p[i+])) flag[i]=true;
if (flag[]&&flag[n-]){
int l=n-,r=;
while(flag[l-]) l--;
while(flag[r+]) r++;
ans.l=l,ans.r=r+n;
}
else{
int l=,r=n-;
while(!flag[l]) l++;
while(!flag[r]) r--;
ans.l=l,ans.r=r;
}
return ans;
} bool solve(){
int ans=inf;
for(int i=;i<n;i++){
fill(dp,dp+*n+,inf);
dp[i]=;
for(int j=;j<n;j++){
int r=i+j;
for(int k=;k<m;k++){
if(q[k].l>r) continue;
int now=min(i+n,q[k].r+);
dp[now]=min(dp[now],dp[r]+q[k].c);
}
}
ans=min(ans,dp[i+n]);
}
if(ans==inf) return false;
printf("%d\n",ans);
return true;
} int main(){
while(~scanf("%d",&n)&&n){
for(int i=;i<n;i++) p[i].read();
p[n]=p[];
scanf("%d",&m);
Point tmp;
int c;
for(int i=;i<m;i++){
tmp.read();
scanf("%d",&c);
q[i]=tra(tmp,c);
}
if (!solve()) printf("Impossible.\n");
}
return ;
}
[Uva10641]Barisal Stadium(区间dp)的更多相关文章
- UVA 10641 - Barisal Stadium(DP + 几何)
题目链接:10641 - Barisal Stadium 题意:逆时针给定n个点,在给m个灯,每一个灯有一个花费,要求最小花费使得全部边能被灯照到 思路:用向量叉积推断向量的顺逆时针关系,从而预处理出 ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- BZOJ 1260&UVa 4394 区间DP
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...
- 区间dp总结篇
前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...
随机推荐
- afinal 文件上传、下载、图片加载实例
// Afinal框架讲解 public class AfinalActivity extends FinalActivity { @ViewInject(id=R.id.bt_afinal_load ...
- rails 字符串 转化为 html
simple_format http://apidock.com/rails/v4.0.2/ActionView/Helpers/TextHelper/simple_format http://api ...
- Zookeeper启动Permission denied
Zookeeper 查询状态,出现如下问题: JMX enabled by default Using config: /usr/zookeeper/zookeeper-/bin/../conf/zo ...
- [原创]关于tomcat启动时时候端口被占用,8080,8005,8009
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 3像素文本偏移bug 解决方案
<style>.box1{ width:100px; height:50px; float:left; background:#dedede;_margin-right:-3px;}.bo ...
- 什么是gitlab CI ?CI代表什么?
CI是Continuous Integration的简称,就是持续集成的意思. 就是说你代码改动了,测试了,提交了,持续集成系统会自动构建(编译等等).持续集成的理念是每个提交的版本都应该是可交付的, ...
- 爬虫 spider
python 2.x # -*- coding: utf-8 -*-import reimport urllib url = 'http://tieba.baidu.com/p/4872795764' ...
- poj piggy-bank
Piggy-Bank Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- 最小生成树prim算法 POJ2031
#include<iostream> #include<algorithm> #include<string.h> #include<ctype.h> ...
- JS字符串转换成数字
方法主要有三种 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数,后者把值转换成浮点数.只有 ...