#include "Head.cpp"

const int N = 10007;

int n, m;

struct Point{
int x,y;
bool operator < (const Point &com) const{
if(y != com.y) return y < com.y;
return x < com.x;
}
}a[N]; int cost[N][N];
int f[N][N]; Point sta[407],tmp[407];
int top;
inline int cross(Point a,Point b,Point c){
return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);
}
inline int Graham(Point *a, int n){
sort(a, a + n);
sta[0] = a[0], sta[1] = a[1];
top = 1;
R(i, 0, n - 1){
while(top && cross(sta[top], a[i], sta[top - 1]) >= 0) --top;
sta[++top] = a[i];
}
int mid = top;
nR(i,n - 2, 0){
while(top > mid && cross(sta[top], a[i], sta[top - 1]) >= 0) --top;
sta[++top] = a[i];
}
return top; }
int Calc(Point a,Point b) {
return abs((a.x + b.x) * (a.y+b.y)) % m;
} int main(){
FileOpen(); while(scanf("%d%d", &n, &m) != EOF) {
R(i,0, n - 1){
io >> a[i].x >> a[i].y;
} int tot = Graham(a,n); if(tot < n) {
printf("I can't cut.\n");
continue;
} Fill(cost, 0);
R(i,0,n - 1)
R(j,i + 2, n - 1){
cost[i][j] = cost[j][i] = Calc(sta[i], sta[j]);
} R(i,0, n - 1){
R(j,0, n - 1){
f[i][j] = 0x7fffffff;
}
f[i][(i + 1) % n] = 0;
}
nR(i,n-3,0)
R(j,i + 2, n -1)
R(k, i + 1, j - 1){
f[i][j] = Min(f[i][j], f[i][k] + f[k][j] + cost[i][k] + cost[k][j]);
} printf("%d\n", f[0][n-1]);
} return 0;
}

段错误什么鬼

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 10007; int n, m; struct Point{
int x,y;
bool operator < (const Point &com) const{
if(y != com.y) return y < com.y;
return x < com.x;
}
}a[N]; int cost[N][N];
int f[N][N]; Point sta[407],tmp[407];
int top;
inline int cross(Point a,Point b,Point c){
return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x);
}
inline int Graham(Point *a, int n){
sort(a + 1, a + n + 1);
sta[0] = a[1], sta[1] = a[2];
top = 1;
R(i, 1, n){
while(top && cross(sta[top], a[i], sta[top - 1]) >= 0) --top;
sta[++top] = a[i];
}
int mid = top;
nR(i,n - 1, 1){
while(top > mid && cross(sta[top], a[i], sta[top - 1]) >= 0) --top;
sta[++top] = a[i];
}
return top; }
int Calc(Point a,Point b) {
return abs((a.x + b.x) * (a.y+b.y)) % m;
} int main(){
//FileOpen(); while(scanf("%d%d", &n, &m) != EOF) {
R(i,1,n){
io >> a[i].x >> a[i].y;
} int tot = Graham(a, n); if(tot < n) {
printf("I can't cut.\n");
continue;
} Fill(cost, 0); R(i,1,n)
R(j,i + 2, n){
cost[i][j] = cost[j][i] = Calc(sta[i], sta[j]);
} R(i,1,n){
R(j,1,n){
f[i][j] = 0x3f3f3f3f;
}
f[i][i % n + 1] = 0;
}
nR(i,n - 2,1){
R(j,i + 2, n){
R(k, i + 1, j - 1){
f[i][j] = Min(f[i][j], f[i][k] + f[k][j] + cost[i][k] + cost[k][j]);
}
}
} printf("%d\n", f[1][n]);
} return 0;
}

ZOJ 3537 (凸包 + 区间DP)(UNFINISHED)的更多相关文章

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

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

  2. zoj 3537 Cake(区间dp)

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

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

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

  4. ZOJ 3537 Cake(凸包+区间DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...

  5. ZOJ 3537 Cake 求凸包 区间DP

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

  6. HDU 6603 Azshara's deep sea(凸包+区间DP)

    由于题目要求,首先维护出一个凸包,然后在凸包上寻找点对关系,用rel[i][j]表示i点和j点之间是否可以连线,又由于维护出来的凸包上的点的个数不多,可以直接枚举点对并枚举所有圆,判断两点直线和圆是否 ...

  7. ZOJ 3469Food Delivery(区间DP)

    Food Delivery Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving prob ...

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

  9. Cake(凸包+区间DP)

    You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into ...

随机推荐

  1. DCM:一个能够改善所有应用数据交互场景的中间件新秀

    摘要:几乎所有涉及应用数据交互的场景都可以通过DCM来改善应用结构,提升开发与计算效率. 本文分享自华为云社区<DCM:中间件家族迎来新成员>,作者: 石臻臻的杂货铺. DCM是什么 现代 ...

  2. python封装发送邮件类

    import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart i ...

  3. 3000帧动画图解MySQL为什么需要binlog、redo log和undo log

    全文建立在MySQL的存储引擎为InnoDB的基础上 先看一条SQL如何入库的: 这是一条很简单的更新SQL,从MySQL服务端接收到SQL到落盘,先后经过了MySQL Server层和InnoDB存 ...

  4. 《Unix 网络编程》14:高级 I/O 函数

    高级 I/O 函数 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ...

  5. 计算机环境变量的配置,以java为例以及eclipse简要设置

    安装JDK时可以不安装公共jre.因为好多软件和浏览器已经默认自带的jre了,或者自动调用系统的了. 在java 中需要设置三个环境变量(1.5之后不需要再设置CLASSPATH了,但需要的话可以设置 ...

  6. 【C++函数题目】重载完成Compare函数

    题目来源链接:https://www.dotcpp.com/oj/problem2008.html 题目讲解链接:http://6o2.cn/1yjJB2  题目描述 利用函数重载完成三个比较大小的C ...

  7. 开发工具-Base64编码/解码

    更新日志 2022年6月10日 新增链接. https://toolb.cn/base64

  8. Javaweb-pom文件

    pom.xml是maven的核心配置文件 <?xml version="1.0" encoding="UTF-8"?> <!--maven版本 ...

  9. 一分钟入门 Babel(下一代 JavaScript 语法的编译器)

    简单来说把 JavaScript 中 es2015/2016/2017/2046 的新语法转化为 es5,让低端运行环境(如浏览器和 node )能够认识并执行.严格来说,babel 也可以转化为更低 ...

  10. js 表面学习 - 认识结构2

    单行注释以 // 开头. 多行注释以 /* 开头,以 */ 结尾. 任何位于 /* 和 */ 之间的文本都会被 JavaScript 忽略. JavaScript 数据类型 JavaScript 变量 ...