#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. jQuery基础入门+购物车案例详解

    jQuery是一个快速.简洁的JavaScript代码库(或JavaScript框架).jQuery设计的宗旨是"write Less,Do More",即倡导写更少的代码,做更多 ...

  2. drools动态增加、修改、删除规则

    目录 1.背景 2.前置知识 1.如何动态构建出一个kmodule.xml文件 2.kmodule.xml应该被谁加载 3.我们drl规则内容如何加载 4.动态构建KieContainer 3.需求 ...

  3. UniqueMergeTree:支持实时更新删除的 ClickHouse 表引擎

    UniqueMergeTree 开发的业务背景 首先,我们看一下哪些场景需要用到实时更新. 我们总结了三类场景: 第一类是业务需要对它的交易类数据进行实时分析,需要把数据流同步到 ClickHouse ...

  4. 如何为Java面试准备项目经验

    1 提出问题 应届生朋友或Java程序员在找Java方面的工作时,一定会需要准备Java项目经验,但事实上不少求职者,是没有项目经验,或者只具有开源社区等的学习项目经验,这样的话,就很有可能在面试时无 ...

  5. 优秀开源平台,前后端分离快速开发平台,一站式多端开发(PC+APP)

    JNPF平台架构介绍 JNPF快速开发平台采用前后端分离技术.采用B/S架构开发,形成一站式开发多端(APP+PC)使用. PC端版本介绍 第一个当然是当下热门的.net core了,运行环境为Vis ...

  6. C#获取PLC信息 (KepServer)二

    具体应用呢,不多说了,上代码,取长补短就是原创 using OPCAutomation; using System; using System.Collections.Generic; using S ...

  7. Nginx安装及支持https代理配置和禁用TSLv1.0、TSLv1.1配置

    Linux安装Nginx Nginx安装及支持https代理配置和禁用TSLv1.0.TSLv1.1配置. 下载安装包 [root@localhost ~]# wget http://nginx.or ...

  8. electron vue

    vue create project vue add vue-cli-plugin-electron-builder node_modules\@vue\cli-service\lib\config\ ...

  9. python常用标准库(压缩包模块zipfile和tarfile)

    常用的标准库 在我们常用的系统windows和Linux系统中有很多支持的压缩包格式,包括但不限于以下种类:rar.zip.tar,以下的标准库的作用就是用于压缩解压缩其中一些格式的压缩包. zip格 ...

  10. Linux常用操作:文件及文件夹

    一.创建 (1)mkdir 创建一个目录 (2)touch 创建一个空文件 注:-r 表示递归操作 二.删除 rm 删除文件 rm -r 删除目录 rm -r * 删除目录下的所有文件 注:-f 不用 ...