见代码。

  1. /*
  2. 凸包(稳定凸包)
  3. 题意:给出一些点,这些点要么是凸包的顶点要么是边上的。
  4. 证明每条边上都至少有3个点。
  5. */
  6. #include<stdio.h>
  7. #include<string.h>
  8. #include<stdlib.h>
  9. #include<algorithm>
  10. #include<iostream>
  11. #include<queue>
  12. #include<map>
  13. #include<stack>
  14. #include<set>
  15. #include<math.h>
  16. using namespace std;
  17. typedef long long int64;
  18. //typedef __int64 int64;
  19. typedef pair<int64,int64> PII;
  20. #define MP(a,b) make_pair((a),(b))
  21. const int maxn = ;
  22. const int inf = 0x7fffffff;
  23. const double pi=acos(-1.0);
  24. const double eps = 1e-;
  25.  
  26. struct Point {
  27. double x,y;
  28. bool operator < ( const Point p ) const {
  29. return y<p.y||(y==p.y&&x<p.x);
  30. }
  31. }res[ maxn ],pnt[ maxn ];
  32. bool flag[ maxn ][ maxn ];//f[i][j]:点ij之间是否还有点
  33. bool ok[ maxn ];//ok[i]:i是否是凸包的顶点
  34.  
  35. double xmult( Point sp,Point ep,Point op ){
  36. return (sp.x-op.x)*(ep.y-op.y)-(sp.y-op.y)*(ep.x-op.x);
  37. }
  38.  
  39. double dis2( Point a,Point b ){
  40. return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
  41. }
  42.  
  43. double dis( Point a,Point b ){
  44. return sqrt( dis2(a,b) );
  45. }
  46.  
  47. bool PointOnLine( Point a,Point L,Point R ){
  48. 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 );
  49. }
  50.  
  51. int Garham( int n ){
  52. int top = ;
  53. sort( pnt,pnt+n );
  54. if( n== ) return ;
  55. else res[ ] = pnt[ ];
  56. if( n== ) return ;
  57. else res[ ] = pnt[ ];
  58. if( n== ) return ;
  59. else res[ ] = pnt[ ];
  60. for( int i=;i<n;i++ ){
  61. while( top>&&xmult( res[top],res[top-],pnt[i] )>= )
  62. top--;
  63. res[ ++top ] = pnt[ i ];
  64. }
  65. int tmp = top;
  66. res[ ++top ] = pnt[ n- ];
  67. for( int i=n-;i>=;i-- ){
  68. while( top!=tmp&&xmult( res[top],res[top-],pnt[i] )>= )
  69. top--;
  70. res[ ++top ] = pnt[ i ];
  71. }
  72. return top;
  73. }
  74.  
  75. int main(){
  76. int T;
  77. scanf("%d",&T);
  78. while( T-- ){
  79. int n;
  80. scanf("%d",&n);
  81. for( int i=;i<n;i++ )
  82. scanf("%lf%lf",&pnt[i].x,&pnt[i].y);
  83. if( n<= ){
  84. puts("NO");
  85. continue;
  86. }//至少要6个点
  87. int cnt = Garham( n );
  88. memset( ok,false,sizeof( ok ) );
  89. memset( flag,false,sizeof( flag ) );
  90. for( int i=;i<n;i++ ){
  91. for( int j=;j<cnt;j++ ){
  92. if( pnt[i].x==res[j].x&&pnt[i].y==res[j].y ){
  93. ok[ i ] = true;
  94. break;
  95. }
  96. }
  97. }
  98. for( int i=;i<n;i++ ){
  99. if( !ok[i] ){
  100. for( int j=;j<cnt;j++ ){
  101. if( PointOnLine( pnt[i],res[j],res[(j+)%cnt]) ){
  102. flag[ j ][ (j+)%cnt ] = true;
  103. }
  104. }
  105. }
  106. }
  107. bool ans = true;
  108. for( int i=;i<cnt;i++ ){
  109. if( flag[ i ][ (i+)%cnt ]==false ){
  110. ans = false;
  111. break;
  112. }
  113. }
  114. if( ans ) printf("YES\n");
  115. else puts("NO");
  116. }
  117. return ;
  118. }

POJ1228+凸包的更多相关文章

  1. POJ1228 Grandpa's Estate 稳定凸包

    POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html   这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...

  2. poj1228(稳定凸包+特判最后一条边)

    题目链接:https://vjudge.net/problem/POJ-1228 题意:我是真的没看懂题意QAQ...搜了才知道.题目给了n个点,问这n个点确定的凸包是否能通过添加点来变成一个新的凸包 ...

  3. POJ1228(稳定凸包问题)

    题目:Grandpa's Estate   题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...

  4. poj1228稳定凸包

    就是给一系列点,看这是不是一个稳定凸包 稳定凸包是指一个凸包不能通过加点来使它扩大面积,也就是说每条边最少有三个点 判断的地方写错了,写了两边循环,其实数组s已经排好了序,直接每三个判断就好了 #in ...

  5. POJ1228:Grandpa's Estate(给定一些点,问是否可以确定一个凸包)

    Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandp ...

  6. 【kuangbin专题】计算几何_凸包

    1.poj1113 Wall 题目:http://poj.org/problem?id=1113 题意:用一条线把若干个点包起来,并且线距离任何一个点的距离都不小于r.求这条线的最小距离是多少? 分析 ...

  7. [poj1113][Wall] (水平序+graham算法 求凸包)

    Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...

  8. ZOJ 3871 Convex Hull(计算几何、凸包)

    题意:给n个点,|x[i]|,|y[i]| <= 1e9.求在所有情况下的子集下(子集点数>=3),凸包的面积和. 这题主要有几个方面,一个是凸包的面积,可以直接用线段的有向面积和求得,这 ...

  9. UVALive 2453 Wall (凸包)

    题意:给你一个多边形的城堡(多个点),使用最短周长的城墙将这个城堡围起来并保证城墙的每个点到城堡上的每个点的距离都不小于l 题解:因为两点间的直线一定比折线短,所以这样做 先使用所有点求得一个凸包,接 ...

随机推荐

  1. 编程语言中的Namespace

    Namespace 1.C struct 2.C++(Pronounced 'see jia-jia' or 'see plus-plus') namespace 3.Python module(s) ...

  2. C#中调用unmanaged DLL

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. Poj 3982 序列

    1.Link: http://poj.org/problem?id=3982 2.Content: 序列 Time Limit: 1000MS   Memory Limit: 65536K Total ...

  4. qml去标题栏

    只要加入"flags: Qt.Window | Qt.FramelessWindowHint "属性就可实现去标题栏. 注意:在使用这个属性的时候要先导入QtQuick.Windo ...

  5. 汇编语言-打印部分ASCII表

    用表格形式显示字符 1. 题目:用表格形式显示ASCII字符 2.要求:按15行×16列的表格形式显示ASCII码为10H-100H的所有字符,即以行为主的顺序及ASCII码递增的次序依次显示对应的字 ...

  6. SQL Server 2008 安装或卸载时提示“重启计算机失败"的解决办法(转)

    安装或卸载SQL Server 遇到错误提示:以前的某个程序安装已在安装计算机上创建挂起的文件操作.运行安装程序之前必须重新启动计算机.如下图: 解决办法: 1.在开始->运行中输入regedi ...

  7. 利用nginx做负载均衡

    round-robin:轮询.以轮询方式将请求分配到不同服务器上,默认 least-connected:最少连接数.将下一个请求分配到连接数最少的那台服务器上 ip-hash :基于客户端的IP地址. ...

  8. VB6-AppendToLog 通过API写入日志

    工作中免不了需要为自己的程序添加日志,我也从网上扒拉了一个老外写的模块,修改修改了下,凑合用吧. Option Explicit '********************************** ...

  9. IP HELPER GetAdaptersAddresses 函数

    自己做的一些笔记,XP以及以后的系统使用: MSDN 函数:http://msdn.microsoft.com/en-US/library/windows/desktop/aa365915(v=vs. ...

  10. ARM-Linux S5PV210 UART驱动(5)----串口的open操作(tty_open、uart_open)

    串口驱动初始化后,串口作为字符驱动也已经注册到系统了,/dev目录下也有设备文件节点了. 那接下来uart的操作是如何进行的呢? 操作硬件之前都是要先open设备,先来分析下这里的open函数具体做了 ...