A - Cake (+极角+凸包)
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std; #define N 310
#define inf 0x7fffffff struct point
{
int x,y;
}dd[N]; int n,p;
int dp[N][N];
int cost[N][N];//边的花费 bool cmp(const point& a,const point &b){
if(a.y == b.y)return a.x < b.x;
return a.y < b.y;
} point save[],temp[]; int xmult(point p1,point p2,point p0){
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} int Graham(point *p,int n){
int i;
sort(p,p + n,cmp);
save[] = p[];
save[] = p[];
int top = ;
for(i = ;i < n; i++){ while(top && xmult(save[top],p[i],save[top-]) >= ) top--;
save[++top] = p[i];
}
int mid = top;
for(i = n - ; i >= ; i--){
while(top>mid&&xmult(save[top],p[i],save[top-]) >= ) top--;
save[++top]=p[i];
}
return top;
} int min(int a,int b){return a<b?a:b;}; void init()
{
int i,j;
for(i = ;i < n;i++){
scanf("%d%d",&dd[i].x,&dd[i].y);
}
for(i = ;i < n;i++){
dp[i][(i+)%n] = ;
cost[i][(i+)%n] = cost[(i+)%n][i]=;
}
} int Dp()
{
int i,j,k;
for(i = n-;i >= ;i--)//注意三个循环的方向
for(j = i+;j < n;j++)//第一个循环从后往前 第二个循环从前往后是为了保证当前用到的状态都已经被计算过了 已经是最优的了
for(k = i+;k < j;k++)
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+cost[i][k]+cost[k][j]);
return dp[][n-];
} int main()
{
int tot, i, j;
while(scanf("%d%d", &n, &p)!=EOF)
{
init();
tot = Graham(dd,n);
for(i = ;i < n;i++)
for(j = i+;j < n;j++){
dp[i][j] = inf;
cost[i][j] = cost[j][i] = ((abs(save[i].x+save[j].x))*(abs(save[i].y+save[j].y)))%p;
}
//判断是否是凸多边形
if(tot < n){
printf("I can't cut.\n");
}
else{
int ans = Dp();
printf("%d\n",ans);
}
}
return ;
}
A - Cake (+极角+凸包)的更多相关文章
- 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)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- ZOJ 3537 Cake 求凸包 区间DP
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...
- NAIPC 2019 A - Piece of Cake(凸包计算)
学习:https://blog.csdn.net/qq_21334057/article/details/99550805 题意:从nn个点中选择kk个点构成多边形,问期望面积. 题解:如果能够确定两 ...
- 区间DP小结
也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好 ...
- [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)
题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...
- POJ 2007 Scrambled Polygon [凸包 极角排序]
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8636 Accepted: 4105 ...
- 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 ...
随机推荐
- Linux就该这么学--命令集合3(文本文件编辑命令)
1.cat命令查看纯文本文件(较短):(cat [选项] [文件]) cat -n showpath.sh 附录: -n 显示行号 -b 显示行号(不包括空行) -A 显示出“不可见”的符号,如空格, ...
- Android App 启动 Activity 创建解析
继承实现类关系: ActivityThread thread = new ActivityThread(); Context->ContextImpl ContextImpl contex ...
- windows下的host文件在哪里,有什么作用?
在Window系统中有个Hosts文件(没有后缀名),在Windows98系统下该文件在Windows目录,在Windows2000/XP系统中位于C:\Winnt\System32\Drivers\ ...
- html5--5-1 了解canvas元素
html5--5-1 了解canvas元素 学习要点 如何在HTML5文档中添加canvas元素 canvas的属性 了解canvas坐标系 了解script元素 绘制一条直线(准确的说是线段) 什么 ...
- 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习
ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding va ...
- hdu-5762 Teacher Bo(抽屉原理+暴力)
题目链接: Teacher Bo Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- codeforces 664C C. International Olympiad(数学)
题目链接: C. International Olympiad time limit per test 1 second memory limit per test 256 megabytes inp ...
- <十三>UML核心视图静态视图之业务用例图
一:uml的核心视图 --->如果说UML是一门语言,上一章学习的参与者等元素是uml的基本词汇,那么视图就是语法.uml通过视图将基元素组织在一起,形成有意义的句子. --->uml可视 ...
- HDFS源码分析三-DataNode实现
3. DataNode 实现( 未完待续 )
- CF-831C
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...