题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010

题目大意:给你n个点,问你顺次连线能否连成多边形?如果能,就输出多边形面积。

面积用向量的叉积去算。然后能否连成多边形就是看这条线跟之前的线有没有交点。

这些在大白书上都有板子。。

代码:

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <string>
  4. #include <iostream>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <cctype>
  8. #include <vector>
  9. #include <map>
  10. #include <set>
  11. #include <iterator>
  12. #include <functional>
  13. #include <cmath>
  14. #include <numeric>
  15. #include <ctime>
  16. using namespace std;
  17. typedef long long LL;
  18. typedef pair<int,int> PII;
  19. typedef vector<int> VI;
  20. #define PB push_back
  21. #define MP make_pair
  22. #define SZ size()
  23. #define CL clear()
  24. #define AA first
  25. #define BB second
  26. #define EPS 1e-8
  27. #define ZERO(x) memset((x),0,sizeof(x))
  28. const int INF = ~0U>>;
  29. const double PI = acos(-1.0);
  30.  
  31. struct POINT{
  32. double x,y;
  33. POINT(double ax=,double ay=):x(ax),y(ay) {}
  34. };
  35. typedef POINT VECTOR;
  36.  
  37. POINT pts[];
  38.  
  39. VECTOR operator- (POINT A,POINT B){
  40. return VECTOR(A.x-B.x,A.y-B.y);
  41. }
  42.  
  43. double CROSS(VECTOR A,VECTOR B){
  44. return A.x*B.y-A.y*B.x;
  45. }
  46.  
  47. double AREA(POINT *p,int n){
  48. double area = ;
  49. for(int i=;i<n-;i++){
  50. area += CROSS(p[i]-p[],p[i+]-p[]);
  51. }
  52. return area/;
  53. }
  54.  
  55. bool SegmentProperIntersection(POINT a1,POINT a2,POINT b1,POINT b2){
  56. double c1 = CROSS(a2-a1,b1-a1) , c2 = CROSS(a2-a1,b2-a1),
  57. c3 = CROSS(b2-b1,a1-b1) , c4 = CROSS(b2-b1,a2-b1);
  58. return c1*c2<EPS && c3*c4<EPS;
  59. }
  60.  
  61. int main(){
  62. int n;
  63. int kase = ;
  64. while( scanf("%d",&n), n ){
  65. if(kase!=) puts("");
  66. bool flag = true;
  67. for(int i=;i<n;i++){
  68. double a,b;
  69. scanf("%lf%lf",&a,&b);
  70. pts[i] = POINT(a,b);
  71. for(int j=;j<i-;j++){
  72. if( SegmentProperIntersection(pts[j],pts[j+],pts[i-],pts[i])) flag = false;
  73. }
  74. }
  75. for(int j=;j<n-;j++){
  76. if( SegmentProperIntersection(pts[j],pts[j+],pts[],pts[n-])) flag = false;
  77. }
  78. double area = fabs(AREA(pts,n));
  79. if( n==||n== ){
  80. printf("Figure %d: Impossible\n",kase++);
  81. continue;
  82. }
  83. if(!flag) printf("Figure %d: Impossible\n",kase++);
  84. else printf("Figure %d: %.2f\n",kase++,area);
  85. }
  86. return ;
  87. }

[ZOJ 1010] Area (计算几何)的更多相关文章

  1. zoj 1010 Area【线段相交问题】

    链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...

  2. [ZJU 1010] Area

    ZOJ Problem Set - 1010 Area Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Jer ...

  3. POJ 1654 Area 计算几何

    #include<stdio.h> #include<string.h> #include<iostream> #include<math.h> usi ...

  4. ZOJ 3157 Weapon --计算几何+树状数组

    题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...

  5. zoj 1010 (线段相交判断+多边形求面积)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds      Mem ...

  6. 1010 Area

    题目要求面积和判断非相邻边不相交.和数学和几何有关系. #include <stdio.h> #include <math.h> #define MISS 0.0000001 ...

  7. POJ2546 Circular Area(计算几何)

                                                                                Circular Area            ...

  8. UVa 1641 ASCII Area (计算几何,水题)

    题意:给定一个矩阵,里面有一个多边形,求多边形的面积. 析:因为是在格子里,并且这个多边形是很规则的,所以所有格子不是全属于多边形就是全不属于,或者一半,并且我们可以根据"/"和“ ...

  9. Hdu-2892 area 计算几何 圆与凸多边形面积交

    题面 题意:有一个凸多边形岛屿,然后告诉你从高空(x,y,h)投下炸弹,爆炸半径r,飞机水平速度和重力加速度,问岛屿被炸了多少 题解:算出来岛屿落地位置,再利用圆与凸多边形面积交 #include&l ...

随机推荐

  1. python之路之正则表达式

    匹配格式^ 匹配字符串的开头$ 匹配字符串的结尾. 除了换行符外的所有字符[...] 用来表示一组字符,,单独列出:[amk]匹配'a','m'或'k'[^..] 不在[]中的字符:[^abc]匹配除 ...

  2. 创建对象的最好方式&最好的继承机制(代码实例)

    /* 创建对象的最好方式:混合的构造函数/原型方式, *用构造函数定义对象的所有非函数属性,用原型方式定义对象的函数属性(方法) */ function People(sname){ this.nam ...

  3. 常见的java 错误--转

    Java常见错误列表: 找不到符号(symbol) 类X是public的,应该被声明在名为X.java的文件中 缺失类.接口或枚举类型 缺失X 缺失标识符 非法的表达式开头 类型不兼容 非法的方法声明 ...

  4. php 同步因子的并发处理

    在php中,如果处理支付时,会涉及到并发. 具体体现在同步通知支付结果和异步通知结果. 拿支付宝来说,同步通知call_back和异步通知notify是没有固定先后顺序的. 有可能notify先通知到 ...

  5. Hadoop常见错误解决

    1. 通过命令和查看日志文件查看hadoop启动和运行情况 在NameNode端,可以通过 tail -100 /var/log/hadoop/hadoop/hadoop-hadoop-namenod ...

  6. VBA 按照文件类型名称打开一个文件

    Application.GetOpenFilename(fileFilter, fileIndex, fileSelectTitle, button, False) fileFilter: 指定能够被 ...

  7. 【python】浅谈enumerate 函数

    enumerate 函数用于遍历序列中的元素以及它们的坐标: >>> for i,j in enumerate(('a','b','c')):  print i,j 0 a 1 b ...

  8. (转)用JQuery实现Fix表头表格

    本文转载自:http://www.cnblogs.com/evlon/archive/2009/06/12/1502239.html 我的技术要点: 1.用两个表,其中一个是表头,另一个是表格做表体 ...

  9. bzoj2764 基因补全

    Description 在生物课中我们学过,碱基组成了DNA(脱氧核糖核酸),他们分别可以用大写字母A,C,T,G表示,其中A总与T配对,C总与G配对.两个碱基序列能相互匹配,当且仅当它们等长,并且任 ...

  10. CentOS 7.0体验与之前版本的不同

    RHEL7和CentOS7出来有一段时间了,拿出点时间研究下,有几个地方跟6和5系列相比改变比较大,估计不少童鞋有点不太习惯.下面简要举例说明改变比较大的要点: 一.CentOS的Services使用 ...