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 ...
随机推荐
- Ubuntu Firefox没有声音的解决方案
安装ubuntu-restricted-extras sudo apt-get install ubuntu-restricted-extras 参考博文:解决ubuntu中firefox没有声音的问 ...
- Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file...
Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file: 把tomcat中的日志删除, ...
- EF 编程经验
http://blog.csdn.net/itmaxin/article/details/47662151 这篇文章里有一下东西可以参考,但是弟二个方法明显是不可行的,因为我做了实验直接attach ...
- eclipse 中PlantUML的安装和使用
安装: 填写的地址:http://hallvard.github.io/plantuml/ 安装完plantUML后,还要下载一个Graphviz https://pan.baidu.com/s/1g ...
- kernel中对文件的读写【学习笔记】【原创】
/*1. 头文件 */ #include <linux/init.h> #include <linux/module.h> #include <linux/modulep ...
- eclipse订制快捷键
步骤: 1.window-preference. 2.在(1)处输入keys,在(2)处输入命令的原来的快捷键,方便找到Binding,在(3)处输入自定义的快捷键.点击“apply and clos ...
- java反射技术实例
java反射技术实例1. [代码][Java]代码 package com.gufengxiachen.java.reflectiontest; public class Person {p ...
- [HAOI 2012] 容易题
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2751 [算法] 考虑k = 0的情况 , 根据乘法原理 : Ans = (n * ( ...
- 洛谷 1072 Hankson 的趣味题——质因数界限讨论
题目:https://www.luogu.org/problemnew/show/P1072 思路是把每个数质因数分解,答案对于每个质因数的次数有选择的区间,通过这个计算. 指数的限制就是上限是b1, ...
- java+poi实现word转html显示
直入正题,需求为页面预览word文档,用的是poi3.8,以下代码支持表格.图片,不支持分页,只支持doc,不支持docx: 1.导jar包 2.java文件 /** * */ import java ...