题目链接:10641 - Barisal Stadium

题意:逆时针给定n个点,在给m个灯,每一个灯有一个花费,要求最小花费使得全部边能被灯照到
思路:用向量叉积推断向量的顺逆时针关系,从而预处理出每一个灯能照到的边,然后因为n个点是环的,所以能够直接扩大两倍,dp时候去枚举起点就可以
状态为dp[i]表示如今照到i条边之前的边所有照亮须要的最小花费
代码:
#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 + 几何)的更多相关文章

  1. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  2. uva 10817(数位dp)

    uva 10817(数位dp) 某校有m个教师和n个求职者,需讲授s个课程(1<=s<=8, 1<=m<=20, 1<=n<=100).已知每人的工资c(10000 ...

  3. 【Uva 10641】 Barisal Stadium

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

  4. [Uva10641]Barisal Stadium(区间dp)

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

  5. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  6. uva 10453 - Make Palindrome(dp)

    题目链接:10453 - Make Palindrome 题目大意:给出一个字符串,通过插入字符使得原字符串变成一个回文串,要求插入的字符个数最小,并且输出最后生成的回文串. 解题思路:和uva 10 ...

  7. uva 10671 - Grid Speed(dp)

    题目链接:uva 10671 - Grid Speed 题目大意:给出N,表示在一个N*N的网格中,每段路长L,如今给出h,v的限制速度,以及起始位置sx,sy,终止位置ex,ey,时间范围st,et ...

  8. uva 1331 - Minimax Triangulation(dp)

    option=com_onlinejudge&Itemid=8&page=show_problem&category=514&problem=4077&mosm ...

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

随机推荐

  1. DOCKER学习心得

    原文:DOCKER学习心得   前言: Docker的主要学习心得来源于<docker技术入门与实战> --2019.1.1->2019.1.5 la 着重从基础部分--实例分析-- ...

  2. [Pug] Template Engine -- Jade/ Pug

    Looking at the follow code: .wrapper - const upName = name && name.toUpperCase(); h2 | Hello ...

  3. Java的压缩、解压及压缩加密、解密解压 样例

    为了节约带宽.加快传送速度,http协议支持gzip的压缩,但假设我们的app与后台不是通过http协议通讯的.那么压缩.解压这个流程须要自己写.以下给出compress和decompress的代码: ...

  4. 使用xerces库的一个注意事项

    作者:朱金灿 来源:http://blog.csdn.net/clever101 使用xerces库解析xml文件,结果出现这样一些链接错误: public: static classxercesc_ ...

  5. ng-cli搭建angular项目框架

    原文地址 https://www.jianshu.com/p/0a8f4b0f29b3 环境准备 以下步骤都不需要事先创建文件夹,只是环境的准备过程,只有到需要搭建项目的时候才需要创建文件夹用来存放项 ...

  6. FOJ (FZU) 1476 矩形的个数 排列组合。

    http://acm.fzu.edu.cn/problem.php?pid=1476  Problem Description 在一个3*2的矩形中,可以找到6个1*1的矩形,4个2*1的矩形3个1* ...

  7. ds finder 唤醒

    http://www.hangge.com/blog/cache/detail_594.html

  8. 【u106】3D模型

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 一座城市建立在规则的n×m网格上,并且网格均由1×1正方形构成.在每个网格上都可以有一个建筑,建筑由若 ...

  9. [Angular2 Router] Guard: CanLoad

    'canLoad' guard can decide whether a lazy load module can be loaded or not. @Injectable() export cla ...

  10. SpringCloud微服务框架搭建

    一.微服务架构 1.1什么是分布式 不同模块部署在不同服务器上 作用:分布式解决网站高并发带来问题 1.2什么是集群 多台服务器部署相同应用构成一个集群 作用:通过负载均衡设备共同对外提供服务 1.3 ...