ZOJ 3537 Cake 求凸包 区间DP
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价。现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价是多少。
思路:首先判断多边形是否是凸多边形,之后就是区间dp了。
求出凸包后,按逆时针来看。
设置dp[i][j]为从顶点i到顶点j所围成凸多边形的最优解。
枚举切点k (i < k < j)
dp[i][j] = min(dp[i][k] + dp[k][j] + cost[i][k] + cost[k][j]);
#include<bits/stdc++.h>
using namespace std;
const int MAXN = ;
struct point {
int x,y;
friend bool operator < (const point &a,const point &b) {
if (a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
}src[MAXN];
int cost[MAXN][MAXN];
int N,P;
int dp[MAXN][MAXN]; point save[MAXN],tmp[MAXN];
int cross(point p0,point p1,point p2) {
return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
} int graphm(point * p,int n) {
sort(p,p + n);
save[] = p[];
save[] = p[];
int top = ;
for(int i = ; i < n ; i++){
while(top && cross(save[top],p[i],save[top-]) >= )top--;
save[++top] = p[i];
} int mid = top;
for(int i = n - ; i >= ; i--){
while(top > mid && cross(save[top],p[i],save[top-]) >= ) top--;
save[++top]=p[i];
}
return top;
} int getcost(point a,point b) {
return (abs(a.x + b.x) * abs(a.y+b.y)) % P;
} int main() {
while (scanf("%d%d",&N,&P) != EOF) {
for (int i = ; i < N ; i++) scanf("%d%d",&src[i].x,&src[i].y);
int num = graphm(src,N);
if (num < N) {
printf("I can't cut.\n");
}
else {
memset(cost,,sizeof(cost));
for (int i = ; i < N ; i++) {
for (int j = i + ; j < N ; j++) cost[i][j] = cost[j][i] = getcost(save[i],save[j]);
}
memset(dp,0x3f,sizeof(dp));
for (int i = ; i < N ; i++) dp[i][(i + ) % N] = ;
for (int d = ; d <= N ; d++) {
for (int i = ; i + d - < N ; i++) {
int j = d + i - ;
for (int k = i + ; k < j ; k++)
dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j] + cost[i][k] + cost[k][j]);
}
}
printf("%d\n",dp[][N - ]);
}
}
return ;
}
ZOJ 3537 Cake 求凸包 区间DP的更多相关文章
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- zoj 3537 Cake (凸包确定+间隔dp)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...
- Cake(凸包+区间DP)
You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into ...
- zoj 3537 Cake 区间DP (好题)
题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...
- ZOJ 3537 Cake(凸包判定+区间DP)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-shaped c ...
- ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)
Description You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut t ...
- zoj 3537 Cake(区间dp)
这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...
- 区间DP Zoj 3537 Cake 区间DP 最优三角形剖分
下面是别人的解题报告的链接,讲解很详细,要注意细节的处理...以及为什么可以这样做 http://blog.csdn.net/woshi250hua/article/details/7824433 我 ...
- ZOJ 3537 Cake (区间DP,三角形剖分)
题意: 给出平面直角坐标系上的n个点的坐标,表示一个多边形蛋糕,先判断是否是凸多边形,若否,输出"I can't cut.".若是,则对这个蛋糕进行3角形剖分,切n-3次变成n-2 ...
随机推荐
- DELPHI的MEMO组件
位于Standard选项卡上,它是对EDIT控件的扩展,可以对多行文本进行显示.输入 和编辑. Lines属性: 该属性实际上为TStrings类型的对象,用来存放Memo对象的文本 TStrings ...
- Qt编码设置
1.Qt Creator -> 工具 -> 选项 -> 环境 - >概要 -> 语言 Qt Creator本身界面的语言选择,与cpp文件编码无关,与可执行文件显示 ...
- BZOJ4784 ZJOI2017仙人掌(树形dp+dfs树)
首先考虑是棵树的话怎么做.可以发现相当于在树上选择一些长度>=2的路径使其没有交,同时也就相当于用一些没有交的路径覆盖整棵树. 那么设f[i]为覆盖i子树的方案数.转移时考虑包含根的路径.注意到 ...
- Apple - Hdu5160
Problem Description We are going to distribute apples to n children. Every child has his/her desired ...
- [洛谷P2161][SHOI2009]会场预约
题目大意:有两种操作: $A\;l\;r:$表示加入区间$[l,r]$,并把与之冲突的区间删除,输出删除的区间的个数,区间$A$于区间$B$冲突当且仅当$A\cap B\not=\varnothing ...
- [洛谷P2408]不同子串个数
题目大意:给你一个字符串,求其中本质不同的字串的个数 题解:同[洛谷P4070][SDOI2016]生成魔咒,只要最后再输出就行了 卡点:无 C++ Code: #include <cstdio ...
- BZOJ4259:残缺的字符串——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4259 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度 ...
- BZOJ2434 [Noi2011]阿狸的打字机 【AC自动机 + fail树 + 树状数组】
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MB Submit: 3610 Solved: 1960 [Submit][S ...
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- MySQL5.6之Index Condition Pushdown(ICP,索引条件下推)-Using index condition
http://blog.itpub.net/22664653/viewspace-1210844/ -- 这篇博客写的更细,以后看 ICP(index condition pushdown)是mysq ...