zoj3537(凸包,最优三角形,区间dp)
来源:互联网 发布:淘宝怎么批量修改价格 编辑:程序博客网 时间:2024/05/16 02:58
You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into several triangle-shaped parts for the invited comers. You have a knife to cut. The trace of each cut is a line segment, whose two endpoints are two vertices of the polygon. Within the polygon, any two cuts ought to be disjoint. Of course, the situation that only the endpoints of two segments intersect is allowed.
The cake's considered as a coordinate system. You have known the coordinates of vexteces. Each cut has a cost related to the coordinate of the vertex, whose formula iscosti, j = |xi + xj| * |yi + yj| % p. You want to calculate the minimum cost.
NOTICE: input assures that NO three adjacent vertices on the polygon-shaped cake are in a line. And the cake is not always a convex.
Input
There're multiple cases. There's a blank line between two cases. The first line of each case contains two integers,N and p (3 ≤ N, p ≤ 300), indicating the number of vertices. Each line of the followingN lines contains two integers, x and y (-10000 ≤x, y ≤ 10000), indicating the coordinate of a vertex. You have known that no two vertices are in the same coordinate.
Output
If the cake is not convex polygon-shaped, output "I can't cut.". Otherwise, output the minimum cost.
Sample Input
3 30 01 10 2
Sample Output
0
题意:求凸n多边形分成n-2个三角形的最小费用
分析:先求凸包,然后用最优三角形求解
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const double eps = 1e-6;const double pi = acos(-1.0);const int INF = 0x3f3f3f3f;const int MOD = 1000000007;#define ll long long#define CL(a) memset(a,0,sizeof(a))#define sqr(a) ((a) * (a))#define dis(a, b) sqrt(sqr(a.x - b.x) + sqr(a.y - b.y))int n,m;int f[305][305],dp[305][305];struct Point{ int x,y;};Point s[305],c[305];int mult(Point p1,Point p2,Point p0)//叉积{ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}bool cmp(const Point& a,const Point &b){ if(a.y == b.y)return a.x < b.x; return a.y < b.y;}int Graham(Point *s, int n)//凸包{ int i; sort(s, s+n, cmp); c[0] = s[0]; c[1] = s[1]; int top = 1; for(i = 0; i < n; i++) { while(top && mult(c[top],s[i],c[top-1]) >= 0)top--; c[++top] = s[i]; } int mid = top; for(i = n - 2; i >= 0; i--) { while(top>mid && mult(c[top],s[i],c[top-1])>=0)top--; c[++top]=s[i]; } return top;}int calc(Point a, Point b)//费用{ return (abs(a.x + b.x) * abs(a.y+b.y)) % m;}int main (){ while (scanf ("%d%d",&n,&m)==2) { for (int i=0; i<n; i++) scanf ("%d%d",&s[i].x,&s[i].y); if (n==3) { cout<<"0"<<endl; continue; } if (Graham(s, n)<n)//求凸包 cout<<"I can't cut."<<endl; else { CL(f); for (int i=0; i<n; i++) { for (int j=i+2; j<n; j++) f[i][j] = f[j][i] = calc(c[i], c[j]); } for (int i=0; i<n; i++) { for (int j=0; j<n; j++) dp[i][j] = INF; dp[i][(i+1)%n]=0; } for (int i=n-3; i>=0; i--)//区间dp求解 { for (int j=i+2; j<n; j++) { for (int k=i+1; k<j; k++) { dp[i][j]=min(dp[i][j], dp[i][k]+dp[k][j]+f[i][k]+f[k][j]); } } } cout<<dp[0][n-1]<<endl; } } return 0;}
- zoj3537 凸包,最优三角形,区间dp
- zoj3537(凸包,最优三角形,区间dp)
- zoj3537 Cake 【凸包+最优三角形划分】
- zoj3537 cake 区间dp+凸包
- zoj 3537 cake (区间DP+凸包+ 最优三角形剖分模型)
- zoj3537(区间dp)
- zoj 3537 cake 切蛋糕 区间DP+凸包+递归 最优三角形剖分
- ZOJ-3537 Cake(区间dp+凸包最优三角形剖分)
- zoj3537 Cake 最优三角剖分(DP)
- 经典问题四. (区间dp) 凸多边形最优三角形划分
- ZOJ 3537-Cake(凸包+最优三角刨分+区间DP)
- zoj 3537 Cake (区间DP x 最优三角形剖分)
- zoj 3537 Cake(区间DP+最优三角形剖分)待续
- ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)
- zoj 3537 Cake 【凸包 + 区间dp】 【最优三角剖分】
- [ACM_SMU_1104]最优矩阵连乘积(区间dp)
- zoj 3537 Cake (凸包判定+区间dp)
- ZOJ 3537 Cake(凸包+区间DP)
- 用fiddler2模拟2G,3G环境下的网络环境
- Cannot create JDBC driver of class '' for connect URL 'null'
- poj 1017
- Mac添加命令别名
- Mac Appium 问题—持续跟进
- zoj3537(凸包,最优三角形,区间dp)
- 火云开发课堂 - 《使用Cocos2d-x 开发3D游戏》系列 第十二节:换装系统
- ORM基本概念及ORM中的映射关系
- socket编程中的setsockopt 用法
- sizeif(i++).sizeof(++i) 的问题
- HashTable与Dictionary的区别说明
- Vector Dictionary HashMap
- play教程 第二课:创建项目
- [POJ 1182]食物链[并查集]