题意:按照顺时针给出操场的周边点,然后给出周围可以建设照明灯的位置,以及在该位置建设照明灯的代价,照明灯照射的范围与操场的边界相切,现在要求一个最小的花费,要求操场的所有边都被照射到。

解题关键:预处理每台灯能够覆盖到的范围,然后对环进行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)的更多相关文章

  1. UVA 10641 - Barisal Stadium(DP + 几何)

    题目链接:10641 - Barisal Stadium 题意:逆时针给定n个点,在给m个灯,每一个灯有一个花费,要求最小花费使得全部边能被灯照到 思路:用向量叉积推断向量的顺逆时针关系,从而预处理出 ...

  2. 【BZOJ-4380】Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  3. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  4. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  5. BZOJ1055: [HAOI2008]玩具取名[区间DP]

    1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Statu ...

  6. poj2955 Brackets (区间dp)

    题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...

  7. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

  8. 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 ...

  9. 区间dp总结篇

    前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...

随机推荐

  1. pinpoint-dubbo插件兼容泛化调用

    背景 dubbo插件中需要记录当前调用的接口和方法,但是在泛化调用的场景下,记录的接口和方法都变成了 com.alibaba.dubbo.rpc.service.GenericService:$inv ...

  2. c++学习笔记(网上资料)

                                    C++笔记       2007-3-22 1. 程序 —— 可执行文件,人发送给计算机的一组指令.         硬件指令是二进制, ...

  3. java中接口的概念及使用(补充final修饰符的使用)

    接口 初期理解,可以是一个特殊的抽象类 当抽象类中的方法都是抽象的,那么该类可以通过接口的形式来表示 class 用于定义类 interface 用于定义接口 接口定义时,格式特点: 1.接口中常见的 ...

  4. python用特殊方法定制类(不全)

    定义在class中不需要直接调用,python的某些函数或操作符会自动的调用对应的特殊方法. 1.python中 __str__和__repr__ __str__()用于显示给用户,而__repr__ ...

  5. iOS项目中获取验证码倒计时及闪烁问题解决方案

    -(void)startTime{ __block int timeout= 59; //倒计时时间 dispatch_queue_t queue = dispatch_get_global_queu ...

  6. Apache 的 httpd.conf 注释

    ServerRoot “/usr/local“ ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是 ...

  7. adobe flash player 下载地址

    1. https://www.adobe.com/cn/products/flashplayer/distribution3.html

  8. Codeforces 571B Minimization:dp + 贪心【前后相消】

    题目链接:http://codeforces.com/problemset/problem/571/B 题意: 给你一个长度为n的数列a[i]. 现在你可以随意改变数字的位置,问你 ∑| a[i] - ...

  9. 用一句SQL取出第 m 条到第 n 条记录的方法

    1 --从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)2 3 SELECT TOP n-m+1 * 4 FROM Table 5 WHERE (id NOT IN (SEL ...

  10. hbase_学习_00_资源帖

    一.官方资料 1.官网:http://hbase.apache.org/ 2.官方文档:HBase 官方文档中文版 二.apache软件下载基地 1. Apache Software Foundati ...