[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来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...
随机推荐
- HackerRank - angry-children 【排序】
题意 求一个序列当中 其 长度为 K 的子序列 中的 最大值 - 最小值 求 这个值 最小是多少 思路 先将序列排序 然后 I = 0, J = K - 1 然后 往下遍历 如果 arr[j] - a ...
- 分布式数据库对比评测(Es,mongodb,redis)基础知识篇
前言 我建议大家看下这个,否则后面你不知道我在说什么. 1.ES数据库相关概念 啥是Es,说白了就是支持文档搜索的分布式数据库,专门方便搜索的,GITHUB京东现在都在用. 1.ES的数据库存放在哪里 ...
- 【leetcode刷题笔记】Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- pulseaudio备注
参考http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?viewmode=compact&topic_id=10102 Ubuntu 8. ...
- 操作系统原理2——OS结构
操作系统原理2——OS结构 计算机系统是由硬件系统和软件系统两部分组成, 操作系统是软件系统的一个组成部分,它是直接在硬件系统的基础上工作的,所以在研究操作系统之前,先必须对计算机系统的结构有一个 ...
- delphi各个版本编译开关值
delphi各个版本编译开关值 {$IFDEF VER80} - Delphi 1{$IFDEF VER90} - Delphi 2{$IFDEF VER100} - Delphi 3{$IFDE ...
- Spark- 数据清洗
输入输出转化工具类 package com.rz.mobile_tag.log import org.apache.spark.sql.Row import org.apache.spark.sql. ...
- Python- and & or 的短路原则
条件1 and 条件2 条件1 or 条件2 短路原则 对于and 如果前面的第一个条件为假,那么这个and前后两个条件组成的表达式的计算结果就一定为假,第二个条件就不会被计算 对于or 如果前面的第 ...
- C++指向函数的指针
直接上代码: #include<iostream> #include<string> #include<vector> using namespace std; t ...
- Python基础-redis模块使用
redis是一个数据库,他的数据全都是存放在内存里面的,redis每秒能支持30w次的读写,存放有两种格式,一种string类型,一种是hash类型 一,操作string类型 r=redis.Redi ...