题目链接

本题也是区间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. JVM 引用类型

    1.强引用 强引用,是在我们的开发工作当中普遍存在的.如果一个对象具有强引用,那就类似我们经常穿的衣服啊等必不可少的生活用品,我们肯定不会把他扔掉,同样jvm的垃圾回收器也不会回收它.当内存空间不足的 ...

  2. jmeter的使用---JDBC

    一.数据库连接配置JDBC Connection Configuration 二.执行sql语句select statement (1)query type类型介绍 select statement: ...

  3. PHP 源码 —— is_array 函数源码分析

    is_array 函数源码分析 本文首发于 https://github.com/suhanyujie/learn-computer/blob/master/src/function/array/is ...

  4. Go_Json序列化

    1. json介绍 2. json格式说明 3. json序列化 3.1 结构体序列化 package main import ( "fmt" "encoding/jso ...

  5. 多租户SaaS的数据库设计模式

    前言 在设计多租户SaaS应用程序时,您必须仔细选择最适合您应用程序需求的租户模型.租户模型确定每个租户的数据如何映射到存储.您选择的租户模式会影响应用程序设计和管理.以后切换到另一个模型有时代价昂贵 ...

  6. py2

    函数相关的 # 生成器相关的# 例1 ll = sum(i for i in range(100000000)) #生成器占资源少 # 例2 def demo(): for i in range(4) ...

  7. putty上传下载文件

    一,需要pscp.exe,习惯上和Putty.exe文件放在一起. 首先需要保证在命令行下可以访问到pscp.exe.可以通过配置Windows的环境变量Path,或者直接通过命令行访问到pscp.e ...

  8. 本次我们使用idea构建springmvc项目

    该案例的github地址:https://github.com/zhouyanger/demo/tree/master/springmvcdemo1 1.首先我们可以创建maven项目,file-&g ...

  9. ajax传map,后端接收并解析

    前端let map = new Map(); map.set(1, 1); map.set(2, 2); map.set(3, 3); //map转obj let obj= Object.create ...

  10. Multism中的一些特殊元器件在哪里找

    1.TLP521-1(光耦)在哪里找 2.单刀双掷开关 3.数码管 indicator:指示器 SEVEN_SEG_DECIMAL_COM_A_BULE: 七段带小数点共阳极,蓝色显示 A:阳极 K: ...