题目链接

本题也是区间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. Django - DRF自带的token认证和JWT区别

    问题重现 当查看DRF 文档时发现DRF内置的token是存储在数据库里,这和我在网上搜索资料时认识的token-based authentication有出入. from rest_framewor ...

  2. Jquery获取html参数, jquery.params.js 获取参数

    ================================ ©Copyright 蕃薯耀 2019年12月31日 http://fanshuyao.iteye.com/ /** * 使用:$.q ...

  3. bugku 点击1000000次

    首先看一下题目发现进入网页之后是这个样的 然后点击一下发现是有变化 然后用F12 然后选择post data 然后输入clicks=1000000 然后就会发现答案 (clicks 是点击的意思)

  4. python evel()的用法

    老生常谈部分: eval(expression[, globals[, locals]]) expression -- 表达式. globals -- 变量作用域,全局命名空间,如果被提供,则必须是一 ...

  5. 吴裕雄 python 机器学习——数据预处理标准化MaxAbsScaler模型

    from sklearn.preprocessing import MaxAbsScaler #数据预处理标准化MaxAbsScaler模型 def test_MaxAbsScaler(): X=[[ ...

  6. Codeforces Round #622 C2.Skyscrapers (hard version)

    This is a harder version of the problem. In this version n≤500000n≤500000 The outskirts of the capit ...

  7. CSS学习(10)行盒盒模型

    常见的行盒:包含具体内容的元素 span.strong.em.i.img.video.audio 显著特点: 1.盒子沿着内容延伸 2.行盒不能设置宽高,调整行盒的宽高,应使用字体大小.行高.字体类型 ...

  8. Laravel 虚拟开发环境 Homestead 密码

    默认数据库账号密码账号: homestead 密码:secret 默认 ssh 账号密码账号:vagrant 密码:vagrant创建默认 root 用户sudo passwd root

  9. Sublime Text3搭建完美开发环境(Python+PHP+Javascript+nodejs+C++)

    一.Sublime配置(如已安装Package Control可跳过) sublime下载地址:http://www.sublimetext.com/3 安装Package Control插件: 直接 ...

  10. Redis安装及局域网访问配置CentOS

    1.安装gcc,用来编译reids 通过命令 sudo yum install gcc 2.安装redis $ wget http://download.redis.io/releases/redis ...