POJ1228
来源:互联网 发布:centos输入法 编辑:程序博客网 时间:2024/05/16 08:24
开始没有看懂题意。。英文啊英文,后来找到了中文的翻译,懂了题目的意思后,就很好求解了。还是用的原来的模板,但是这道题的意思就是判断一条边上是否有大于等于3的钉子数,所以只要返回的凸包的点数*2<=本身的钉子数就好了。咦。突然间发现好像是因为POJ的数据太弱了。。。因为假设一条边上只有两枚钉子而其他边上有许多的钉子,那我岂不是被卡。啊。。。原来是水数据才让我过的啊~~~
上代码:
#include<cstdio>
#include<algorithm>
using namespace std;
struct point { int x, y; };
bool mult(point sp, point ep, point op){
return (sp.x - op.x) * (ep.y - op.y)
>= (ep.x - op.x) * (sp.y - op.y);
}
bool operator < (const point &l, const point &r){
return l.y < r.y || (l.y == r.y && l.x < r.x);
}
int graham(point pnt[], int n, point res[]){
int i, len, k = 0, top = 1;
sort(pnt, pnt + n);
if (n == 0) return 0; res[0] = pnt[0];
if (n == 1) return 1; res[1] = pnt[1];
if (n == 2) return 2; res[2] = pnt[2];
for (i = 2; i < n; i++) {
while (top && mult(pnt[i], res[top], res[top-1]))
top--;
res[++top] = pnt[i];
}
len = top; res[++top] = pnt[n - 2];
for (i = n - 3; i >= 0; i--) {
while (top!=len && mult(pnt[i], res[top], res[top-1])) top--;
res[++top] = pnt[i];
}
return top;
}
main(){
struct point pnt[60],res[60],p;
int t,i,n,top;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=0;i<=n-1;i++){
scanf("%d%d",&pnt[i].x,&pnt[i].y);
}
top=graham(pnt,n,res);
if(top*2<=n)
printf("YES\n");
else
printf("NO\n");
}
}
- poj1228
- POJ1228
- poj1228
- poj1228
- POJ1228 Grandpa's Estate
- Poj1228(稳定凸包)
- poj1228 - Grandpa's Estate
- POJ1228--Grandpa's Estate
- POJ1228-Grandpa's Estate
- Poj1228 Grandpa's Estate
- POJ1228(稳定凸包问题)
- POJ1228(稳定凸包问题)
- poj1228 [ SDOI2009 ] --稳定凸包
- POJ1228 Grandpa's Estate 还是凸包
- 凸包,有利于理解凸包极角排序poj1228
- POJ1228-Grandpa's Estate(凸包)
- poj1228 (判断凸包的完整性)
- poj1228 Grandpa's Estate 凸包
- 普利姆算法通俗讲解
- Code Optimization Using the GNU C Compiler
- 关于AVR I/O 的驱动能力的介绍
- 利用fedora 15 DVD ISO 镜像制作安装源
- ASP.NET MVC 3让依赖注入实现得更简单
- POJ1228
- 代码的持续可用性
- 数据结构--立体层次结构
- 一些关于phpize的信息
- Spin控件使用总结
- SQL Server 2005 COM+ 目录要求警告的解决方法
- Linux:驱动程序直接编译到内核(源自国嵌的视频教学)
- php和 mysql安装
- 读书笔记(Windows 消息机制)