zoj 3537 Cake 区间DP (好题)
题意:切一个凸边行,如果不是凸包直接输出。然后输出最小代价的切割费用,把凸包都切割成三角形。
先判断是否是凸包,然后用三角形优化。
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+w[i][k]+w[j][k]);
w[i][j]代表i到j点的切割费用。
dp[i][j]:表示以i到j点的最小费用。则可把凸边行分成三个部分的费用。两个凸边行(i,k),(k,j)和两条边的费用(i,k),(j,k),k为枚举的三角形顶点。
Zoj 3537 Cake (DP_最优三角形剖分)
//#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<algorithm>
#include<vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
const int maxn=;
struct Point{
int x, y;
Point(int x=, int y=):x(x),y(y) { }
}p[maxn]; // typedef Point Vector; int w[maxn][maxn],dp[maxn][maxn],n,m; // Vector operator + (const Vector& A, const Vector& B)
// {
// return Vector(A.x+B.x, A.y+B.y);
// }
// Vector operator - (const Point& A, const Point& B)
// {
// return Vector(A.x-B.x, A.y-B.y);
// }
// double Cross(const Vector& A, const Vector& B)
// {
// return A.x*B.y - A.y*B.x;
// } // Vector Rotate(const Vector& A, double rad)
// {
// return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
// } // bool operator < (const Point& p1, const Point& p2)
// {
// return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y);
// } // bool operator == (const Point& p1, const Point& p2)
// {
// return p1.x == p2.x && p1.y == p2.y;
// }
// // 点集凸包
// // 如果不希望在凸包的边上有输入点,把两个 <= 改成 <
// // 如果不介意点集被修改,可以改成传递引用
// vector<Point> ConvexHull(vector<Point> p)
// {
// // 预处理,删除重复点
// sort(p.begin(), p.end());
// p.erase(unique(p.begin(), p.end()), p.end()); // int n = p.size();
// int m = 0;
// vector<Point> ch(n+1);
// for(int i = 0; i < n; i++)
// {
// while(m > 1 && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
// ch[m++] = p[i];
// }
// int k = m;
// for(int i = n-2; i >= 0; i--)
// {
// while(m > k && Cross(ch[m-1]-ch[m-2], p[i]-ch[m-2]) <= 0) m--;
// ch[m++] = p[i];
// }
// if(n > 1) m--;
// ch.resize(m);
// return ch;
// }
Point save[],temp[];
int xmult(Point p1,Point p2,Point p0){ return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool cmp(const Point &a,const Point &b){ if(a.y == b.y)return a.x < b.x;
return a.y < b.y;
}
int Graham(Point *p,int n) {
int i;
sort(p,p + n,cmp);
save[] = p[];
save[] = p[];
int top = ;
for(i = ;i < n; i++){ while(top && xmult(save[top],p[i],save[top-]) >= )top--;
save[++top] = p[i];
}
int mid = top;
for(i = n - ; i >= ; i--){ while(top>mid&&xmult(save[top],p[i],save[top-])>=)top--;
save[++top]=p[i];
}
return top;
} int main(){
// freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m)){
for(int i=;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y);
clc(dp,);
clc(w,);
int v;
v=Graham(p,n);
// printf("%d\n",(int)v.size());
if(v<n) printf("I can't cut.\n");
else{
for (int i = ; i < n; ++i)
for (int j = i + ; j < n; ++j)
w[i][j] = w[j][i] =(abs(save[i].x + save[j].x) * abs(save[i].y+save[j].y)) % m;
for (int i = ; i < n; ++i) {
for (int j = ; j < n; ++j)
dp[i][j] = inf;
dp[i][(i+)%n] = ;
}
for (int i = n - ; i >= ; --i)
for (int j = i + ; j < n; ++j)
for (int k = i + ; k <= j - ; ++k)
dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j]+w[i][k]+w[k][j]);
printf("%d\n",dp[][n-]);
}
}
return ;
}
zoj 3537 Cake 区间DP (好题)的更多相关文章
- zoj 3537 Cake(区间dp)
这道题目是经典的凸包的最优三角剖分,不过这个题目给的可能不是凸包,所以要提前判定一下是否为凸包,如果是凸包的话才能继续剖分,dp[i][j]表示已经排好序的凸包上的点i->j上被分割成一个个小三 ...
- 区间DP Zoj 3537 Cake 区间DP 最优三角形剖分
下面是别人的解题报告的链接,讲解很详细,要注意细节的处理...以及为什么可以这样做 http://blog.csdn.net/woshi250hua/article/details/7824433 我 ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- poj 2955 Brackets (区间dp基础题)
We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...
- 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
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...
- zoj 3537 Cake (凸包确定+间隔dp)
Cake Time Limit: 1 Second Memory Limit: 32768 KB You want to hold a party. Here's a polygon-sha ...
- 状态压缩---区间dp第一题
标签: ACM 题目 Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is ...
随机推荐
- 【斜率DP】BZOJ 1911:特别行动队
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 3006 Solved: 1360[Submit][Statu ...
- 如何使用PHP实现一个WebService
WSDL WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问.这种文 ...
- 读取tiled地图
原地址:http://www.unity蛮牛.com/thread-20854-1-1.html Tile是一个非常好用的地图编辑器,一直以来我都在找支持tilemap的unity2D插件,但是找 ...
- Android支付接入(四):联通VAC计费
原地址:http://blog.csdn.net/simdanfeg/article/details/9012031 注意事项: 1.联通支付是不需要自己标识软硬计费点的,当平台申请计费点的时候会提交 ...
- 【C++基础】 各种“虚”总结(ing...)
虚基类,虚函数,虚析构函数,纯虚函数,虚函数表(待补充) 一.虚基类——在继承方式(public / private)之前加 virtual class B1: virtual public B0{} ...
- Android 文字链接 文字点击时的背景颜色
案例:实现“忘记密码?”这个链接,并且在按下的时候改变颜色. 方法一:这个可以用TextView实现: 主界面main.xml: <?xml version="1.0" en ...
- 【BZOJ 2300】 2300: [HAOI2011]防线修建 (动态凸包+set)
2300: [HAOI2011]防线修建 Description 近来A国和B国的矛盾激化,为了预防不测,A国准备修建一条长长的防线,当然修建防线的话,肯定要把需要保护的城市修在防线内部了.可是A国上 ...
- Mysql一主多从和读写分离配置简记
近期开发的系统中使用MySQL作为数据库,由于数据涉及到Money,所以不得不慎重.同时,用户对最大访问量也提出了要求.为了避免Mysql成为性能瓶颈并具备很好的容错能力,特此实现主从热备和读写分离. ...
- Tiny4412之C语言实现流水灯,Tiny4412裸机程序[3]
在前边我们使用汇编完成了一个流水灯实验: Tiny4412汇编流水灯代码,Tiny4412裸机LED操作 ---- - -- -- -- - -- -- 修改: # ${MKBL2} ${SOURCE ...
- Unity NGUI弧形血条的制作
unity版本:4.6 NGUI版本:3.6. (转载请注明参考链接及作者) 参考链接:http://www.cnblogs.com/louissong/p/3841656.html,作者:博客园 L ...