题目链接

本题也是区间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. python 实现 md文档自动编号

    目录 1. 原理 2. 运行方法 3. 效果 4. 代码 1. 原理 正则匹配对相应字符串进行替换 2. 运行方法 python md_convert.py [a.md, b.md,...] # 转换 ...

  2. 2019南昌网络赛 hello 2019

    这道题和一道2017,2016的类似. A string t is called nice if a string “2017” occurs in t as a subsequence but a ...

  3. 关于java中MD5加密(可直接使用)

    本文转自:http://www.cnblogs.com/solove/archive/2011/10/18/2216715.html 上部分是转载的关于字符串的加密,后半部分则比较全,包括字符串.文件 ...

  4. docker 报错 docker: Error response from daemon: driver failed....iptables failed:

    现象: [root@localhost test]# docker run --name postgres1 -e POSTGRES_PASSWORD=password -p : -d postgre ...

  5. idea中的springboot+gradle项目报错springboot configuration annotation processor not found in classpath

    idea中的springboot项目,打开某个类run.halo.app.config.properties.HaloProperties.java,报错(使用gradle编译): springboo ...

  6. iOS 自动化打包发布(Fastlane+ Jenkins+蒲公英)

    安装 Xcode 命令行工具:xcode-select --install 安装 fastlane:sudo gem install fastlane --verbose 安装成功后查看版本:fast ...

  7. red hat 报错:apt-get:找不到命令

    Linux有两个系列:一个是RedHat系列,一个是Debian系列. RedHat系列:Redhat.Centos.Fedora等 Debian系列:Debian.Ubuntu等 RedHat 系列 ...

  8. react脚手架和深入理解jsx语法

    react的mvc和vue的mvvm vue的mvvm属于双向绑定,view层,model数据层,vm实现双向绑定的控制层 此种模式,再某一类项目种很有优势:管理系统 ( OA, ERP , CRM ...

  9. ClickOnce部署,修改deploymentProvider

    打开 以.application 为后缀的文件,找到并修改 <deploymentProvider codebase="" /> 即可

  10. js克隆一个对象

    我们知道,对象类型在赋值的过程中其实是复制了地址,所以如果改变了一方,其他都会被改变.我们应该如何克隆一个对象,并且避免这种现象的发生呢? 方法一:Object.assign function cop ...