Description

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 is
costi, 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 following
N 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 3
0 0
1 1
0 2

Sample Output

0
题意:给定n个点的坐标,先问这些点能否组成一个凸包,假设是凸包,问用不相交的线来切这个凸包使得凸包仅仅由三角形组成。依据costi, j = |xi + xj| * |yi + yj| % p
算切线的费用,问最少的分割费用。 思路:第一次做凸包,抄模板,ZeroClock 图画的非常好,就不反复了
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1005;
const int inf = 1000000000; struct point {
int x, y;
} p[maxn], save[maxn], tmp[maxn];
int cost[maxn][maxn], n, m;
int dp[maxn][maxn]; int dis(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 *p,int n) {
sort(p,p + n,cmp);
save[0] = p[0];
save[1] = p[1];
int top = 1;
for (int i = 0;i < n; i++) {
while (top && dis(save[top],p[i],save[top-1]) >= 0) top--;
save[++top] = p[i];
} int mid = top;
for(int i = n - 2; i >= 0; i--) {
while (top > mid && dis(save[top],p[i],save[top-1])>=0) top--;
save[++top]=p[i];
}
return top;
} int Count(point a, point b) {
return (abs(a.x+b.x) * abs(a.y+b.y)) % m;
} int main() {
while (scanf("%d%d",&n,&m) != EOF) {
for (int i = 0; i < n; ++i)
scanf("%d%d",&p[i].x,&p[i].y); int tot = Graham(p,n); //求凸包
if (tot != n) printf("I can't cut.\n");
else {
memset(cost,0,sizeof(cost));
for (int i = 0; i < n; ++i)
for (int j = i + 2; j < n; ++j)
cost[i][j] = cost[j][i] = Count(save[i],save[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--)
for (int j = i + 2; j < n; j++)
for (int k = i + 1; k <= j - 1; k++)
dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+cost[i][k]+cost[k][j]);
printf("%d\n",dp[0][n-1]);
}
}
return 0;
}

ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)的更多相关文章

  1. ZOJ 3537 Cake (区间DP,三角形剖分)

    题意: 给出平面直角坐标系上的n个点的坐标,表示一个多边形蛋糕,先判断是否是凸多边形,若否,输出"I can't cut.".若是,则对这个蛋糕进行3角形剖分,切n-3次变成n-2 ...

  2. ZOJ 3537 (凸包 + 区间DP)(UNFINISHED)

    #include "Head.cpp" const int N = 10007; int n, m; struct Point{ int x,y; bool operator &l ...

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

  4. UVA - 1331 Minimax Triangulation (区间dp)(最优三角剖分)

    题目链接 把一个多边形剖分成若干个三角形,使得其中最大的三角形面积最小. 比较经典的一道dp问题 设dp[l][r]为把多边形[l,r]剖分成三角形的最大三角形面积中的最小值,则$dp[l][r]=m ...

  5. zoj 3537 Cake 区间DP (好题)

    题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...

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

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

  7. ZOJ 3537 Cake 求凸包 区间DP

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

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

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

  9. zoj 3537 Cake(区间dp)

    这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...

随机推荐

  1. OpenCV2学习笔记(十五):利用Cmake高速查找OpenCV函数源代码

    在使用OpenCV时,在对一个函数的调用不是非常了解的情况下,通常希望查到该函数的官方声明.而假设想进一步研究OpenCV的函数,则必须深入到源码. 在VS中我们能够选中想要查看的OpenCV函数,点 ...

  2. 倍福TwinCAT(贝福Beckhoff)基础教程5.1 TwinCAT-2 运行可执行文件

    个人认为这条命令做的参数比较混乱,PATHSTR是指可执行文件路径+最终文件名,DIRNAME是指可执行文件路径,最后COMNDLINE可有可无,是指带参数运行启动的文件   测试可以正常运行     ...

  3. 系统重装 U盘安装XP操作系统开机出现提示txtsetup.sif怎么办

    你的这个问题 是安装xp时把xp做成u盘出现的 原因是xp没有在根本上支持这种安装 到win7后才支持的 解决方法有以下几种 1,刻录成cd 2重新下载xp ghost版的不会出现这个问题 3证实Ul ...

  4. iOS_新版iOS11 UITbleView适配的一些问题及解决方法

    // tableView 偏移20/64适配 if (@available(iOS 11.0, *)) { self.tableView.contentInsetAdjustmentBehavior ...

  5. C# Redis Server分布式缓存编程(一)

    这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...

  6. redis配置不当可导致服务器被控制

    服务器配置不当包括三个部分:1.Redis服务使用ROOT账号启动2.Redis服务无密码认证或者使用的是弱口令进行认证3.服务器开放了SSH服务,而且允许使用密钥登录 简单的写下过程 测试环境vic ...

  7. mkdir的参数-p的作用

    mkdir -p /nfs 也就是加上-p参数,之前只知道是递归创建目录,于是就发问了,得到的答案是: -p, --parents              no error if existing, ...

  8. eclipse 创建maven web错误Cannot change version of project facet Dynamic web module to 3.1解决方案

    Dynamic Web Module 选择“3.1”,java选择“1.8”,报错:Cannot change version of project facet Dynamic web module ...

  9. Git(四):理解和使用分支

         分支是Git的核心内容之中的一个,本章将介绍分支的一些知识,这里将继续使用前面创建的版本号库. 假设你跳过了前面章节直接进入本章.能够从Github上克隆这个版本号库: $ git clon ...

  10. 【数据挖掘】关联分析之Apriori(转载)

    [数据挖掘]关联分析之Apriori 1.Apriori算法 如果一个事务中有X,则该事务中则很有可能有Y,写成关联规则 {X}→{Y} 将这种找出项目之间联系的方法叫做关联分析.关联分析中最有名的问 ...