uva 10641 (来当雷锋的这回....)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f; int n,m;
int f[100];
struct point{
double x,y;
point(double xx = 0,double yy = 0){
this->x = xx;
this->y = yy;
}
void read(){
scanf("%lf%lf",&x,&y);
}
}p[100];
struct Q{
int l,r,c;
}q[1005];
bool judge(point pp,point p1,point p2){///向量叉积。推断顺逆时针时注意三个点的先后位置
/// <0是就是第一个向量在第二个向量的逆时针方向;
return ((p1.x-pp.x)*(p2.y-pp.y)-(p2.x-pp.x)*(p1.y - pp.y)) < -eps;
}
Q tra(point t,int c){
Q ans;
bool flag[100];
memset(flag,false,sizeof(flag));
for(int i = 0; i < n; i++){
if(judge(t,p[i],p[i+1])){///推断能不能照到这条边
///(实际上推断转化成了照到点);
flag[i] = true;
}
}
///以下是处理得出的数据,保存下每一个灯所能照到的最左端和最右端;
if(flag[n-1]&&flag[0]){
int left = n-1;
while(flag[left-1]){left--;}
int right = 0;
while(flag[right+1]){right++;}
ans.l = left;
ans.r = right + n;
}
else{
int left = 0,right = n-1;
while(!flag[left]){left++;}
while(!flag[right]){right--;}
ans.l = left;
ans.r = right;
}
ans.c = c;
return ans;
}
bool solve()
{
int ans = inf;
for(int i = 0; i < n; i++){
memset(f,inf,sizeof(f));
f[i] = 0;
for(int j = 0; j < n; j++){
int r = i + j;///从第i个点開始往后数了j个;
///多定义这么一个层次,能够使状态的转移变得有序
for(int k = 0; k < m; k++){
if(q[k].l > r) continue;///当前点与该灯照亮的最左点之间有空隔,就不符合開始更新的条件;
if(q[k].r < r) continue;///这是个剪枝,去掉也对;就是不再考虑不会成为最优解的情况;
int now = min(q[k].r + 1, i + n);///依据区间右端点往后更新。可是一旦更新过了i+n就要将端点定为i+n;
f[now] = min(f[now],f[r] + q[k].c);
}
}
ans = min(ans,f[i+n]);
}
if(ans == inf) return false;
printf("%d\n",ans);
return true;
}
int main()
{
while(scanf("%d",&n) != EOF){
if(n == 0) break;
for(int i = 0; i < n; i++){
p[i].read();
}
p[n] = p[0]; scanf("%d",&m);
point temp;int c;
for(int i = 0; i < m; i++){
temp.read();
scanf("%d",&c);
q[i] = tra(temp,c);
} if(!solve()) printf("Impossible.\n");
}
return 0;
}
uva 10641 (来当雷锋的这回....)的更多相关文章
- UVA 10739 String to Palindrome(动态规划 回文)
String to Palindrome 题目大意:给出一个字符串s,现在可以进行3种操作(添加字母,删除字母,替换字母),将其变成回文串,求出最少的操作次数.比如abccda,可以用删除操作,删除b ...
- UVA 11584 Paritioning by Palindromes(动态规划 回文)
题目大意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串.比如racecar本身就是回文串:fastcar只能分成7个单字母的回文串:aaadbccb最少可分成3个回文串:aaa. ...
- UVA 12378 Ball Blasting Game 【Manacher回文串】
Ball Blasting Game Morteza is playing a ball blasting game. In this game there is a chain of differe ...
- uva 10716 Evil Straw Warts Live(贪心回文串)
这道题目我用了一上午才做出来,还是看的别人的思路,尽管没有看代码做的有点慢.代码能力还是得加强啊.思维 得缜密.不能想当然,要有根据,写上的代码要有精确度.省的以后还得慢慢调试 思路:贪心.每次都查看 ...
- UVA 10641 - Barisal Stadium(DP + 几何)
题目链接:10641 - Barisal Stadium 题意:逆时针给定n个点,在给m个灯,每一个灯有一个花费,要求最小花费使得全部边能被灯照到 思路:用向量叉积推断向量的顺逆时针关系,从而预处理出 ...
- 【Uva 10641】 Barisal Stadium
[Link]: [Description] 输入一个凸n(3≤n≤30)边形体育馆和多边形外的m(1≤m≤1000)个点光源,每个点光 源都有一个费用值.选择一组点光源,照亮整个多边形,使得费用值总和 ...
- Uva 11584,划分成回文串
题目链接:https://uva.onlinejudge.org/external/115/11584.pdf 题意: 一个字符串,将它划分一下,使得每个串都是回文串,求最少的回文串个数. 分析: d ...
- UVA - 11584 划分字符串的回文串子串; 简单dp
/** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...
- uva 10453 【回文串区间dp】
Uva 10453 题意:给定字符串,问最少插入多少个字符使其变成回文串,并任意输出一种结果. 题解:和Uva 10739类似,这里是只能增加.类似定义dp[i][j]表示子串Si...Sj变为回文串 ...
随机推荐
- WebApi不支持跨域访问
- 洛谷P4014 分配问题(费用流)
题目描述 有 nn 件工作要分配给 nn 个人做.第 ii 个人做第 jj 件工作产生的效益为 c_{ij}cij .试设计一个将 nn 件工作分配给 nn 个人做的分配方案,使产生的总效益最大. ...
- HDU 3830 Checkers(二分+lca)
Description Little X, Little Y and Little Z are playing checkers when Little Y is annoyed. So he wan ...
- python小项目之头像右上角加数字
pillow介绍 一.Image类的属性:1.Format 2.Mode 3.Size 4.Palette 5.Info 二.类的函数:1.New 2.Open 3.Ble ...
- vue 2.x axios 封装的get 和post方法
import axios from 'axios' import qs from 'qs' export class HttpService { Get(url, data) { return new ...
- Linux下安装桌面
1. 安装之前先测试是否有桌面 2. 建立yum源文件 3. 挂载好光盘(/rhel自己创建) 4. 使用yum list 查看 ...
- 「JavaSE 重新出发」05.01.02 hashCode 方法、toString 方法
hashCode 方法 散列码(hash code)是由对象导出的一个整形值(可以是负数).其是没有规律的,如果x与y是两个不同的对象,则x.hashCode()与y.hashCode()基本上不会相 ...
- js数组去重的四种方式
// 删除重复的 function only(arr){ for(var i=0;i<arr.length;i++){ for(var j = i+1;j<arr.length;j++){ ...
- RxSwift 之变换操作
https://www.aliyun.com/jiaocheng/349821.html RxSwift入坑解读-你所需要知道的各种概念 http://www.open-open.com/lib/vi ...
- day03 Python3的安装
目录 Python的安装 Python下载 Python3安装 环境变量 添加环境变量 在CMD中运行Python Python的安装 Python可在多个操作系统(Windows,Linux,Mac ...