Cake ZOJ - 3537
本题也是区间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的更多相关文章
- zoj 3537 Cake 区间DP (好题)
题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...
- zoj 3537 Cake (凸包确定+间隔dp)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- 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 ...
- 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 ...
- zoj 3537 Cake(区间dp)
这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...
- ZOJ 3537 Cake
区间DP. 首先求凸包判断是否为凸多边形. 如果是凸多边形:假设现在要切割连续的一段点,最外面两个一定是要切一刀的,内部怎么切达到最优解就是求子区间最优解,因此可以区间DP. #include< ...
- 区间DP Zoj 3537 Cake 区间DP 最优三角形剖分
下面是别人的解题报告的链接,讲解很详细,要注意细节的处理...以及为什么可以这样做 http://blog.csdn.net/woshi250hua/article/details/7824433 我 ...
- ZOJ 3537 Cake 求凸包 区间DP
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...
随机推荐
- PHP高并发和大流量怎么解决?
PHP高并发和大流量的解决方案 一 高并发的概念 在互联网时代,并发,高并发通常是指并发访问.也就是在某个时间点,有多少个访问同时到来. 二 高并发架构相关概念 1.QPS (每秒查询率) : 每秒钟 ...
- liunx详解-2
linux安装与配置 安装配置 虚拟机配置1G内存,1核CPU,50G硬盘,网络地址转换(NAT,主机作为路由构建内网) 镜像文件:http://mirror.nsc.liu.se/centos-st ...
- Java-POJ1000-A+B Problem
- 「题解」「JZOJ-4238」纪念碑
题目 在 \(N\times M\) 的网格中,有 \(P\) 个矩形建筑,求一个最大边长的正方形,使得网格中能找到一个放置正方形的地方,不会与建筑重合. 保证 \(N,M\le 10^6,P\le ...
- opencv:霍夫直线检测
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- vue指令及组件
复习 """ vue: 为什么选择vue - 综合其他框架优点,轻量级,中文API,数据驱动,组件化开发,数据的双向绑定,虚拟DO 渐进式js框架 - 选择性控制 - 创 ...
- vue使用axios访问后台接口
链接1:https://segmentfault.com/a/1190000012635783#item-2 // axios 使用post方式传递参数,后端接受不到,怎么解决 链接2:http ...
- Docker - CentOS 7 安装
1. 概述 安装 docker markdown 显示有点问题 代码块里的 后面应该跟一个换行, 但是没有跟 这样会导致部分命令直接执行没有反应 2. 环境 os CentOS7 用户 root 3 ...
- confluence-工具安装
wiki 企业级的应用知识库,个人感觉还是很不错的,所以自己本地也搭一个玩玩: 1.下载confluence wget https://downloads.atlassian.com/software ...
- element-ui表头render-header 传自定义参数
最近用到 element 的表格的 render-header 这个属性查了文档 发现: 发现它会返回部分参数 但是因为考虑要工程化,需要自定义传入参数,后来找度娘 ,发现是可以自定义传参的 :re ...