POJ1228+凸包
见代码。
- /*
- 凸包(稳定凸包)
- 题意:给出一些点,这些点要么是凸包的顶点要么是边上的。
- 证明每条边上都至少有3个点。
- */
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<algorithm>
- #include<iostream>
- #include<queue>
- #include<map>
- #include<stack>
- #include<set>
- #include<math.h>
- using namespace std;
- typedef long long int64;
- //typedef __int64 int64;
- typedef pair<int64,int64> PII;
- #define MP(a,b) make_pair((a),(b))
- const int maxn = ;
- const int inf = 0x7fffffff;
- const double pi=acos(-1.0);
- const double eps = 1e-;
- struct Point {
- double x,y;
- bool operator < ( const Point p ) const {
- return y<p.y||(y==p.y&&x<p.x);
- }
- }res[ maxn ],pnt[ maxn ];
- bool flag[ maxn ][ maxn ];//f[i][j]:点ij之间是否还有点
- bool ok[ maxn ];//ok[i]:i是否是凸包的顶点
- double xmult( Point sp,Point ep,Point op ){
- return (sp.x-op.x)*(ep.y-op.y)-(sp.y-op.y)*(ep.x-op.x);
- }
- double dis2( Point a,Point b ){
- return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
- }
- double dis( Point a,Point b ){
- return sqrt( dis2(a,b) );
- }
- bool PointOnLine( Point a,Point L,Point R ){
- return ( fabs(xmult( a,L,R ))<eps )&&( (a.x-L.x)*(a.x-R.x)<eps )&&( (a.y-L.y)*(a.y-R.y)<eps );
- }
- int Garham( int n ){
- int top = ;
- sort( pnt,pnt+n );
- if( n== ) return ;
- else res[ ] = pnt[ ];
- if( n== ) return ;
- else res[ ] = pnt[ ];
- if( n== ) return ;
- else res[ ] = pnt[ ];
- for( int i=;i<n;i++ ){
- while( top>&&xmult( res[top],res[top-],pnt[i] )>= )
- top--;
- res[ ++top ] = pnt[ i ];
- }
- int tmp = top;
- res[ ++top ] = pnt[ n- ];
- for( int i=n-;i>=;i-- ){
- while( top!=tmp&&xmult( res[top],res[top-],pnt[i] )>= )
- top--;
- res[ ++top ] = pnt[ i ];
- }
- return top;
- }
- int main(){
- int T;
- scanf("%d",&T);
- while( T-- ){
- int n;
- scanf("%d",&n);
- for( int i=;i<n;i++ )
- scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
- if( n<= ){
- puts("NO");
- continue;
- }//至少要6个点
- int cnt = Garham( n );
- memset( ok,false,sizeof( ok ) );
- memset( flag,false,sizeof( flag ) );
- for( int i=;i<n;i++ ){
- for( int j=;j<cnt;j++ ){
- if( pnt[i].x==res[j].x&&pnt[i].y==res[j].y ){
- ok[ i ] = true;
- break;
- }
- }
- }
- for( int i=;i<n;i++ ){
- if( !ok[i] ){
- for( int j=;j<cnt;j++ ){
- if( PointOnLine( pnt[i],res[j],res[(j+)%cnt]) ){
- flag[ j ][ (j+)%cnt ] = true;
- }
- }
- }
- }
- bool ans = true;
- for( int i=;i<cnt;i++ ){
- if( flag[ i ][ (i+)%cnt ]==false ){
- ans = false;
- break;
- }
- }
- if( ans ) printf("YES\n");
- else puts("NO");
- }
- return ;
- }
POJ1228+凸包的更多相关文章
- POJ1228 Grandpa's Estate 稳定凸包
POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html 这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...
- poj1228(稳定凸包+特判最后一条边)
题目链接:https://vjudge.net/problem/POJ-1228 题意:我是真的没看懂题意QAQ...搜了才知道.题目给了n个点,问这n个点确定的凸包是否能通过添加点来变成一个新的凸包 ...
- POJ1228(稳定凸包问题)
题目:Grandpa's Estate 题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...
- poj1228稳定凸包
就是给一系列点,看这是不是一个稳定凸包 稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点 判断的地方写错了,写了两边循环,其实数组s已经排好了序,直接每三个判断就好了 #in ...
- POJ1228:Grandpa's Estate(给定一些点,问是否可以确定一个凸包)
Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandp ...
- 【kuangbin专题】计算几何_凸包
1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...
- [poj1113][Wall] (水平序+graham算法 求凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- ZOJ 3871 Convex Hull(计算几何、凸包)
题意:给n个点,|x[i]|,|y[i]| <= 1e9.求在所有情况下的子集下(子集点数>=3),凸包的面积和. 这题主要有几个方面,一个是凸包的面积,可以直接用线段的有向面积和求得,这 ...
- UVALive 2453 Wall (凸包)
题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...
随机推荐
- 编程语言中的Namespace
Namespace 1.C struct 2.C++(Pronounced 'see jia-jia' or 'see plus-plus') namespace 3.Python module(s) ...
- C#中调用unmanaged DLL
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Poj 3982 序列
1.Link: http://poj.org/problem?id=3982 2.Content: 序列 Time Limit: 1000MS Memory Limit: 65536K Total ...
- qml去标题栏
只要加入"flags: Qt.Window | Qt.FramelessWindowHint "属性就可实现去标题栏. 注意:在使用这个属性的时候要先导入QtQuick.Windo ...
- 汇编语言-打印部分ASCII表
用表格形式显示字符 1. 题目:用表格形式显示ASCII字符 2.要求:按15行×16列的表格形式显示ASCII码为10H-100H的所有字符,即以行为主的顺序及ASCII码递增的次序依次显示对应的字 ...
- SQL Server 2008 安装或卸载时提示“重启计算机失败"的解决办法(转)
安装或卸载SQL Server 遇到错误提示:以前的某个程序安装已在安装计算机上创建挂起的文件操作.运行安装程序之前必须重新启动计算机.如下图: 解决办法: 1.在开始->运行中输入regedi ...
- 利用nginx做负载均衡
round-robin:轮询.以轮询方式将请求分配到不同服务器上,默认 least-connected:最少连接数.将下一个请求分配到连接数最少的那台服务器上 ip-hash :基于客户端的IP地址. ...
- VB6-AppendToLog 通过API写入日志
工作中免不了需要为自己的程序添加日志,我也从网上扒拉了一个老外写的模块,修改修改了下,凑合用吧. Option Explicit '********************************** ...
- IP HELPER GetAdaptersAddresses 函数
自己做的一些笔记,XP以及以后的系统使用: MSDN 函数:http://msdn.microsoft.com/en-US/library/windows/desktop/aa365915(v=vs. ...
- ARM-Linux S5PV210 UART驱动(5)----串口的open操作(tty_open、uart_open)
串口驱动初始化后,串口作为字符驱动也已经注册到系统了,/dev目录下也有设备文件节点了. 那接下来uart的操作是如何进行的呢? 操作硬件之前都是要先open设备,先来分析下这里的open函数具体做了 ...