标签:style blog class code tar color
#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 + 几何),布布扣,bubuko.com
UVA 10641 - Barisal Stadium(DP + 几何)
标签:style blog class code tar color
原文地址:http://blog.csdn.net/accelerator_/article/details/25117155