ZOJ 3537 (凸包 + 区间DP)(UNFINISHED)
#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)的更多相关文章
- zoj 3537 Cake 区间DP (好题)
题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[ ...
- zoj 3537 Cake(区间dp)
这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...
- 区间DP Zoj 3537 Cake 区间DP 最优三角形剖分
下面是别人的解题报告的链接,讲解很详细,要注意细节的处理...以及为什么可以这样做 http://blog.csdn.net/woshi250hua/article/details/7824433 我 ...
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- ZOJ 3537 Cake 求凸包 区间DP
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...
- HDU 6603 Azshara's deep sea(凸包+区间DP)
由于题目要求,首先维护出一个凸包,然后在凸包上寻找点对关系,用rel[i][j]表示i点和j点之间是否可以连线,又由于维护出来的凸包上的点的个数不多,可以直接枚举点对并枚举所有圆,判断两点直线和圆是否 ...
- ZOJ 3469Food Delivery(区间DP)
Food Delivery Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving prob ...
- 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 ...
- 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 ...
随机推荐
- Mysql 存储引擎以及 SQL语句
存储引擎 文件格式有很多种,针对不同的文件格式会有对应的不同存储方式和处理机制. 针对不同的数据应该有对应的不同处理机制来存储. 存储引擎就是不同的处理机制 MySQL主要的存储引擎 Innodb 是 ...
- IDEA找不到类但实际存在的问题解决
不知道某天开始Idea就开始抽风了. 现象: 一个service的接口类,就在同一个包下,但总是找不到,编辑器一直标红 编译可以通过 说明类本身应该是没什么问题的.问题是怎么重新编译重新reload ...
- 基于.NetCore开发博客项目 StarBlog - (10) 图片瀑布流
系列文章 基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客? 基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目 基于.NetC ...
- 物联网lora无线数传模块应用案例:LoRawan网关通信技术
什么是LoRa LoRa(Long Range) 无线通信技术是 Semtech 在2012年开发出来的一款适合物联网使用的射频IC.其设计理念为低功耗.长距离.低成本.网路简单.易于扩展的无线数传技 ...
- 皓远的第二次博客作业(最新pta集,链表练习及期中考试总结)
前言: 知识点运用:正则表达式,有关图形设计计算的表达式和算法,链表的相关知识,Java类的基础运用,继承.容器与多态. 题量:相较于上次作业,这几周在java方面的练习花了更多的精力和时间,所要完成 ...
- UiPath官网认证中文教程
RPA之家公众号:RPA之家 RPA之家官网:http://rpazj.com 斗鱼直播:http://www.douyu.com/rpazj UiPath中文社区QQ群:465630324 RPA& ...
- zabbix配置邮件报警
1.yum源安装sendmail,sendmail-cf和mailx 2.关闭postfix,/etc/init.d/postfix stop chkconfig posfix off 3.启动sen ...
- mysql备份数据库linux
备份数据库 问题描述: 我们用的是mysql,以今天遇到的情况为例,我们是在两台服务器上要搭相同的平台,部署完成后页面报错,发现是数据库的问题,我们打开数据库查看,确实数据库中少建一个wind数据 ...
- python各种BUG报错解决
报错1 python学习交流群:660193417### Could not build atari-py: Command '['cmake', '..']' returned non-zero e ...
- 拉取服务器上的项目,svn认证失败
解决方案: 在服务器上找到对应的项目路径,并修改authz: 我的是因为[group]组下(下图中34行),我写的是[demo:/],改为[/]就可以了.