#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 (+极角+凸包)的更多相关文章

  1. 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 ...

  2. zoj 3537 Cake (凸包确定+间隔dp)

    Cake Time Limit: 1 Second      Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...

  3. ZOJ 3537 Cake(凸包+区间DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...

  4. ZOJ 3537 Cake 求凸包 区间DP

    题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...

  5. NAIPC 2019 A - Piece of Cake(凸包计算)

    学习:https://blog.csdn.net/qq_21334057/article/details/99550805 题意:从nn个点中选择kk个点构成多边形,问期望面积. 题解:如果能够确定两 ...

  6. 区间DP小结

    也写了好几天的区间DP了,这里稍微总结一下(感觉还是不怎么会啊!). 但是多多少少也有了点感悟: 一.在有了一点思路之后,一定要先确定好dp数组的含义,不要模糊不清地就去写状态转移方程. 二.还么想好 ...

  7. [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)

    题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...

  8. POJ 2007 Scrambled Polygon [凸包 极角排序]

    Scrambled Polygon Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8636   Accepted: 4105 ...

  9. 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 ...

随机推荐

  1. iOS 第三方登录之 QQ登录

    一. 首先需要下载腾讯qq登录所需的库,下载地址是http://open.qq.com/ . 需要用到的有TencentOpenAPI.framework 和TencentOpenApi_IOS_Bu ...

  2. Tomcat之catalina.out日志分割

    可参考:http://meiling.blog.51cto.com/6220221/1911769 本人尚未验证.

  3. UVA10561 Treblecross —— SG博弈

    题目链接:https://vjudge.net/problem/UVA-10561 题意: 两个人玩游戏,轮流操作:每次往里面添加一个X,第一个得到XXX的获胜. 题解: 详情请看<训练指南&g ...

  4. html5--5-8 绘制圆/弧

    html5--5-8 绘制圆/弧 学习要点 掌握绘制圆弧的方法 矩形的绘制方法 rect(x,y,w,h)创建一个矩形 strokeRect(x,y,w,hx,y,w,h) 绘制矩形(无填充) fil ...

  5. DB2删除表分区

    近日,由于部门数据库读库空间过小,提出删除掉两个月之前日志表的分区(数据库分区是按时间月分区),记述如下: 上网搜索资料发现删除表分区大概分这么几步: 1.查询需要删除掉的分区: select t.D ...

  6. C语言system()函数:执行shell命令

    头文件:#include <stdlib.h> 定义函数:int system(const char * string); 函数说明:system()会调用fork()产生子进程, 由子进 ...

  7. Opencv— — image offset

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  8. IDEA 设置背景颜色及字号

    intellij IDEA 设置背景颜色   File--> Settings 2. Appearance & Behavior --> Appearance 设置边框背景颜色 3 ...

  9. java.lang.NoSuchMethodException: com.sun.proxy.$Proxy

    删掉了@Transactional注解,结果成功了 是这个注解造成的. 是ssh2的整合强制我们使用分层架构.

  10. HTTP Status 500 - Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

    如果在service类上面没有添加注解,出现异常 @Transactional