#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 (来当雷锋的这回....)的更多相关文章

  1. UVA 10739 String to Palindrome(动态规划 回文)

    String to Palindrome 题目大意:给出一个字符串s,现在可以进行3种操作(添加字母,删除字母,替换字母),将其变成回文串,求出最少的操作次数.比如abccda,可以用删除操作,删除b ...

  2. UVA 11584 Paritioning by Palindromes(动态规划 回文)

    题目大意:输入一个由小写字母组成的字符串,你的任务是把它划分成尽量少的回文串.比如racecar本身就是回文串:fastcar只能分成7个单字母的回文串:aaadbccb最少可分成3个回文串:aaa. ...

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

  4. uva 10716 Evil Straw Warts Live(贪心回文串)

    这道题目我用了一上午才做出来,还是看的别人的思路,尽管没有看代码做的有点慢.代码能力还是得加强啊.思维 得缜密.不能想当然,要有根据,写上的代码要有精确度.省的以后还得慢慢调试 思路:贪心.每次都查看 ...

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

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

  6. 【Uva 10641】 Barisal Stadium

    [Link]: [Description] 输入一个凸n(3≤n≤30)边形体育馆和多边形外的m(1≤m≤1000)个点光源,每个点光 源都有一个费用值.选择一组点光源,照亮整个多边形,使得费用值总和 ...

  7. Uva 11584,划分成回文串

    题目链接:https://uva.onlinejudge.org/external/115/11584.pdf 题意: 一个字符串,将它划分一下,使得每个串都是回文串,求最少的回文串个数. 分析: d ...

  8. UVA - 11584 划分字符串的回文串子串; 简单dp

    /** 链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34398 UVA - 11584 划分字符串的回文串子串: 简单 ...

  9. uva 10453 【回文串区间dp】

    Uva 10453 题意:给定字符串,问最少插入多少个字符使其变成回文串,并任意输出一种结果. 题解:和Uva 10739类似,这里是只能增加.类似定义dp[i][j]表示子串Si...Sj变为回文串 ...

随机推荐

  1. Android开发之控制手机音频

    本实例通过MediaPlayer播放一首音乐并通过AudioManager控制手机音频.关于AudioManager的具体解释可參照:Android开发之AudioManager(音频管理器)具体解释 ...

  2. 0x41 并查集

    太菜了才做到并查集啊啊啊啊啊啊啊啊啊啊啊 还是很有收获的说 水 bzoj4195: [Noi2015]程序自动分析 好题 poj1456 感受到并查集传递性的美妙啊!对于一个商品,去找他过期前那天的集 ...

  3. 0x37 容斥原理与莫比乌斯函数

    多重集的组合数公式得记下.cf451E就是这个的裸题 #include<cstdio> #include<iostream> #include<cstring> # ...

  4. 利用DBMS_SQLTUNE优化SQL

    DBMS_SQLTUNE优化SQL是在oracle10g才出来的新特性,使用它能很大程度上方便对sql的分析和优化.执行DBMS_SQLTUNE包进行sql优化需要有advisor的权限: stat& ...

  5. Windows下Java JDK安装和环境变量配置

    [Java攻城狮学习路线](http://www.cnblogs.com/apollospotatolikett/p/8665123.html 1.JDK下载 下载地址:http://www.orac ...

  6. Core Java(六)

    面向对象语言特性 (一) (一)  static 作用于 变量,方法,代码块 静态变量:被类的所有对象共享   在类加载时被加载   优先于对象 Student.country = "中国& ...

  7. vue 2.x axios 封装的get 和post方法

    import axios from 'axios' import qs from 'qs' export class HttpService { Get(url, data) { return new ...

  8. Maintain Aspect Ratio Mixin

    Maintain Aspect Ratio Mixin Maintain the aspect ratio of a div with CSS RESPONSIVE ASPECT RATIOS WIT ...

  9. 发现个很变态的css问题,记录下。

    注意看Ul:nth-child(){} 本来是一一对应的,因为后来改版在div中加了<h1></h1>标记后,竟然自动后移了.... 不可思议,莫明奇妙

  10. Java中更精确的计时

    我们一般的java运输计时代码是 long begintime = System.currentTimeMillis(); //运算代码 long endtinme=System.currentTim ...