题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000)。

题目链接:http://poj.org/problem?id=1228

——>>初看这题,好别扭,不知道要做什么。。。

其实,是这样的:先求凸包,然后看凸包每一条边所在直线上有多少个点,至少需要3个。

假设一条边的所在直线只有2个点,那么可适当地在这两个点中间加一个或者几个点,使新图形仍是凸包,这时候就不能确定原来的凸包了。

假设一条边的所在直线上有3个以上的点,如果在其中两点间扩展一个点,所形成的图形是凹的,所以不能扩展,即边就确定了。

#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int maxn = 1000 + 10;
const double eps = 1e-10; int dcmp(double x){
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
} struct Point{
double x;
double y;
Point(double x = 0, double y = 0):x(x), y(y){}
bool operator < (const Point& e) const{
return x < e.x || (dcmp(x - e.x) == 0 && y < e.y);
}
}p[maxn], q[maxn]; typedef Point Vector; Vector operator + (Point A, Point B){
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B){
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Point A, double p){
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p){
return Vector(A.x / p, A.y / p);
} double Cross(Vector A, Vector B){
return A.x * B.y - B.x * A.y;
} int ConvexHull(Point *p, int n, Point* ch){ //求凸包
sort(p, p + n);
int m = 0;
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--;
return m;
} double ConvexPolygonArea(Point *p, int n){
double area = 0;
for(int i = 1; i < n-1; i++) area += Cross(p[i]-p[0], p[i+1]-p[0]);
return area / 2;
} int main()
{
int t, n;
scanf("%d", &t);
while(t--){
bool ok = 1;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
if(n < 3) ok = 0;
else{
int m = ConvexHull(p, n, q);
if(m < 6) ok = 0;
if(ok) for(int i = 2; i < m; i++){
if(dcmp(Cross(q[i] - q[i-1], q[i] - q[i-2])) != 0){
ok = 0;
break;
}
while(dcmp(Cross(q[i] - q[i-1], q[i] - q[i-2])) == 0) i++;
}
if(dcmp(ConvexPolygonArea(q, m)) == 0) ok = 0;
}
if(ok) puts("YES");
else puts("NO");
}
return 0;
}

最新文章

  1. Prime Generator
  2. python面向对象中的__init__方法怎么理解?
  3. MySQL数据故障时备份与恢复
  4. 编译jsoncpp库以及要注意的问题
  5. C# 文字转声音
  6. c#sqlhelper之用法
  7. init()和deinit()
  8. Windows操作系统单文件夹下到底能存放多少文件及单文件的最大容量
  9. Android必会小功能总结
  10. mysql安装启动教程(两种方法)
  11. [转载] cookie、JS记录及跳转到页面原来的位置
  12. python - 面向对象(二)
  13. UVa10986_Sending email(最短)(白皮书图论的话题)
  14. xampp打开显示缺少运行库的解决方法
  15. POJ1064 Cable master(二分 浮点误差)
  16. The connection string &#39;MysqlEF&#39; in the application&#39;s configuration file does not contain the require异常
  17. MCS-51单片机存储地址空间划分
  18. .net系统的MD5加密方法
  19. 单元测试UI
  20. 58. Length of Last Word (String)

热门文章

  1. 注册flash.ocx inno setup (转)
  2. Opencv2.4.4作图像旋转和缩放
  3. hdu 1575 Tr A(矩阵快速幂乘法优化算法)
  4. jQuery关于mouseover和mouseenter的区别
  5. .net 加密错误:填充无效,无法移除
  6. sql显示12个月数据
  7. NOPI 导出excel 通用方法
  8. 连接mysql数据库2+操作入门
  9. Linux挂载硬盘出错:$LogFile indicates unclean shutdown (0, 0)
  10. JSON 解析第三方框架