题目链接

本题也是区间dp三角剖分板子题,只不过加入了判断是否是凸包,计算顺序要用凸包顺序(凸包板)

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;
typedef pair<int,int> pii; const double eps = 1e-;
const int INF = 0x3f3f3f3f; int dp[][];
int f[][]; int dcmp(double x) {
if(fabs(x) < eps) return ;
return x < ?-:;
} struct Point {
double x, y;
Point friend operator - (Point a, Point b) {
return {a.x-b.x, a.y-b.y};
}
} points[], s[]; double crossProduct(Point a, Point b) {
return a.x*b.y - a.y*b.x;
} double dis(Point a, Point b) {
Point c = a-b;
return sqrt(c.x*c.x+c.y*c.y);
} bool isConvexHull(int n) {
sort(points+, points++n, [&](Point& a, Point& b) {
return a.y < b.y || (a.y == b.y && a.x < b.x);
});
sort(points+, points++n, [&](Point& a, Point& b) {
double x = crossProduct(a-points[], b-points[]);
if(dcmp(x) > || (dcmp(x) == && dcmp(dis(a, points[])-dis(a, points[]))<)) return true;
return false;
});
s[] = points[], s[] = points[];
int t = ;
for(int i = ; i <= n; ++i) {
while(t >= && dcmp(crossProduct(s[t] - s[t-], points[i] - s[t-])) <= ) t--;
s[++t] = points[i];
}
return t == n;
} int cost(Point a, Point b, int p) {
return (abs(int(a.x+b.x)) * abs(int(a.y+b.y))) % p;
} void run_case() {
int n, p;
while(cin >> n >> p) {
for(int i = ; i <= n; ++i) cin >> points[i].x >> points[i].y;
bool flag = isConvexHull(n);
if(!flag) {
cout << "I can't cut.\n";
} else {
for(int i = ; i <= n; i++){
for(int j = i+; j <= n; j++){
f[i][j] = f[j][i] = cost(s[i],s[j], p);
}
}
for(int i = n-; i >= ; --i) {
for(int j = i+; j <= n; ++j) {
dp[i][j] = INF;
for(int k = i+; k < j; ++k)
dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]+f[i][k]+f[k][j]);
}
}
cout << dp[][n] << "\n";
}
} } int main() {
ios::sync_with_stdio(false), cin.tie();
cout.flags(ios::fixed);cout.precision();
//int t; cin >> t;
//while(t--)
run_case();
cout.flush();
return ;
}

Cake ZOJ - 3537的更多相关文章

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

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

  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)

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

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

  6. zoj 3537 Cake(区间dp)

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

  7. ZOJ 3537 Cake

    区间DP. 首先求凸包判断是否为凸多边形. 如果是凸多边形:假设现在要切割连续的一段点,最外面两个一定是要切一刀的,内部怎么切达到最优解就是求子区间最优解,因此可以区间DP. #include< ...

  8. 区间DP Zoj 3537 Cake 区间DP 最优三角形剖分

    下面是别人的解题报告的链接,讲解很详细,要注意细节的处理...以及为什么可以这样做 http://blog.csdn.net/woshi250hua/article/details/7824433 我 ...

  9. ZOJ 3537 Cake 求凸包 区间DP

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

随机推荐

  1. SpringMVC开发RESTful接口

    概念: 什么是REST? REST是Representational State Transfer的缩写.翻译为"表现层状态转化",restful是一种接口设计风格,它不是一个协议 ...

  2. Flask 教程 第十九章:Docker容器上的部署

    本文翻译自The Flask Mega-Tutorial Part XIX: Deployment on Docker Containers 这是Flask Mega-Tutorial系列的第十九部分 ...

  3. git上传时出现ERROR: Repository not found.的解决办法

    今天在上传时出现错误,原因是之前更改了gitee上的个人空间地址,导致找不到.需要重新配置 https://gitee.com/help/articles/4114#article-header0

  4. QT+VS后中文字符乱码问题

    在VS中写QT项目会出现中文乱码现象,尤其是控件的中文乱码以及qDebug()时候中文乱码通用的解决办法: 在头文件(.h)前面加上如下代码: #ifdef WIN32 #pragma executi ...

  5. if a != None:

    >>> x = 1 >>> not x False >>> x = [1] >>> not x False >>&g ...

  6. Nuxt项目文件目录结构解释

    |-- .nuxt // Nuxt自动生成,临时的用于编辑的文件,build |-- assets // 用于组织未编译的静态资源入LESS.SASS 或 JavaScript |-- compone ...

  7. IPSec无法建立?注意第一阶段hash sha !

    该篇注意记录一下,有些情况下,我们配置了IPSec ,但是就是无法建立,发现连第一阶段都无法建立起来. 1.检查配置无问题 2.开启debug crypto isakmp发现有IKE的重传 3.sho ...

  8. Java - JVM - jinfo

    1. 概述 jinfo java 运行时的配置工具 查看 设置 2. 环境 idea 2018.2 java jdk8 3. 准备 写个 死循环 概述 需要查看 jvm 的信息, 必须有个运行中的 j ...

  9. yii2 password hash生成与验证方法

    1.生成 $password是明文.如:123456 $this->password_hash = Yii::$app->security->generatePasswordHash ...

  10. 架构师必备技能指南:SaaS(软件即服务)架构设计

    1.介绍 从计算机诞生开始,就伴随着计算机应用程序的演变.简短的回顾历史,我们可以清楚的看到应用程序发生的巨大变化.上世纪70年代中期,随着个人PC机的爆炸式增长以及程序员的崛起,让计算机的计算能力得 ...