UVA 10641 - Barisal Stadium(DP + 几何)
题目链接:10641 - Barisal Stadium
#include <stdio.h>
#include <string.h> const double eps = 1e-6;
const int N = 105;
const int M = 1005;
int n, m, i, j, dp[N];
bool flag[N];
#define INF 0x3f3f3f3f
#define min(a,b) ((a)<(b)?(a):(b)) struct Point {
double x, y;
Point(double x = 0, double y = 0) {
this->x = x;
this->y = y;
}
void read() {
scanf("%lf%lf", &x, &y);
}
} p[N], o; struct Q {
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;
} Q tra(Point t, int c) {
Q ans;
ans.c = c;
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[0] && flag[n - 1]) {
int l = n - 1, r = n;
while (flag[l - 1]) l--;
while (flag[r - n + 1]) r++;
ans.l = l; ans.r = r; } else {
int l = 0, r = n - 1;
while (!flag[l]) l++;
while (!flag[r]) r--;
ans.l = l; ans.r = r;
}
if (ans.r < ans.l) ans.r += n;
return ans;
} bool solve() {
int ans = INF;
for (int i = 0; i < n; i++) {
memset(dp, INF, sizeof(dp));
dp[i] = 0;
for (int j = 0; j < n; j++) {
int r = i + j;
for (int k = 0; k < m; k++) {
if (q[k].l > r) continue;
int now = min(i + n, q[k].r + 1);
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 (i = 0; i < n; i++) p[i].read();
p[n] = p[0];
scanf("%d", &m);
Point tmp;
int c;
for (i = 0; i < m; i++) {
tmp.read();
scanf("%d", &c);
q[i] = tra(tmp, c);
}
if (!solve()) printf("Impossible.\n");
}
return 0;
}
UVA 10641 - Barisal Stadium(DP + 几何)的更多相关文章
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
- uva 10817(数位dp)
uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...
- 【Uva 10641】 Barisal Stadium
[Link]: [Description] 输入一个凸n(3≤n≤30)边形体育馆和多边形外的m(1≤m≤1000)个点光源,每个点光 源都有一个费用值.选择一组点光源,照亮整个多边形,使得费用值总和 ...
- [Uva10641]Barisal Stadium(区间dp)
题意:按照顺时针给出操场的周边点,然后给出周围可以建设照明灯的位置,以及在该位置建设照明灯的代价,照明灯照射的范围与操场的边界相切,现在要求一个最小的花费,要求操场的所有边都被照射到. 解题关键:预处 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- uva 10453 - Make Palindrome(dp)
题目链接:10453 - Make Palindrome 题目大意:给出一个字符串,通过插入字符使得原字符串变成一个回文串,要求插入的字符个数最小,并且输出最后生成的回文串. 解题思路:和uva 10 ...
- uva 10671 - Grid Speed(dp)
题目链接:uva 10671 - Grid Speed 题目大意:给出N,表示在一个N*N的网格中,每段路长L,如今给出h,v的限制速度,以及起始位置sx,sy,终止位置ex,ey,时间范围st,et ...
- uva 1331 - Minimax Triangulation(dp)
option=com_onlinejudge&Itemid=8&page=show_problem&category=514&problem=4077&mosm ...
- UVa 11825 - Hackers' Crackdown DP, 枚举子集substa = (substa - 1)&sta 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
随机推荐
- ios开发网络学习AFN框架的使用一:get和post请求
#import "ViewController.h" #import "AFNetworking.h" @interface ViewController () ...
- 事件处理之一:两种方式:监听器与回调 分类: H1_ANDROID 2013-10-31 10:26 3250人阅读 评论(0) 收藏
Android组件的事件处理有2种方式: 1.基于监听器的事件处理方式:先定义组件,然后为组件设定监听器. 详见http://blog.csdn.net/jediael_lu/article/deta ...
- Jupyter Notebook 常用快捷键
Jupyter Notebook 提供了比 IPython 美观的多得多的可视化形式.(比如对于 pandas 下的 DataFrame 的展示,df.head(5)) Jupyter Noteboo ...
- 在SSMS查询分析器中显示行号
有网友问及,看到Insus.NET帮他解决问题分享的截屏时,发现代码中有显示行号.而他的没有. Step1: Go to Tools > Options Step2: In the Option ...
- html5-5 HTML5表单元素和内嵌框架
html5-5 HTML5表单元素和内嵌框架 一.总结 一句话总结:单选框和多选框选的时候外面加label就可以实现选后面文字也可以选中了 1.html5如何实现文件上传? 必须加上enctype ...
- jquery 点击其他地方
<script type="text/javascript"> function stopPropagation(e) { if (e.stopPropagation) ...
- Navigation Pane不能设置显示标题
https://msdn.microsoft.com/VBA/Word-VBA/articles/view-showheading-method-word https://social.msdn.mi ...
- tspitr(tablespace point in time recovery)实验
===========环境模拟================= -----------模拟数据---------------- SYS@ORCL>create tablespace test ...
- Android5.0网络之ipv6
移动设备的大量兴起势必进一步加强ip地址不足的危机. ipv6或许成为一种比較好的选择方案. ipv6地址的获取分为两种方式:无状态:有状态 无状态:通过接收路由公告(RA)来设置自己的ipv6地址 ...
- [TypeScript] Using ES6 and ESNext with TypeScript
TypeScript is very particular about what is and isn't allowed in a TS file to protect you from commo ...