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

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

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

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

代码:

 #include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <functional>
#include <cmath>
#include <numeric>
#include <ctime>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define PB push_back
#define MP make_pair
#define SZ size()
#define CL clear()
#define AA first
#define BB second
#define EPS 1e-8
#define ZERO(x) memset((x),0,sizeof(x))
const int INF = ~0U>>;
const double PI = acos(-1.0); struct POINT{
double x,y;
POINT(double ax=,double ay=):x(ax),y(ay) {}
};
typedef POINT VECTOR; POINT pts[]; VECTOR operator- (POINT A,POINT B){
return VECTOR(A.x-B.x,A.y-B.y);
} double CROSS(VECTOR A,VECTOR B){
return A.x*B.y-A.y*B.x;
} double AREA(POINT *p,int n){
double area = ;
for(int i=;i<n-;i++){
area += CROSS(p[i]-p[],p[i+]-p[]);
}
return area/;
} bool SegmentProperIntersection(POINT a1,POINT a2,POINT b1,POINT b2){
double c1 = CROSS(a2-a1,b1-a1) , c2 = CROSS(a2-a1,b2-a1),
c3 = CROSS(b2-b1,a1-b1) , c4 = CROSS(b2-b1,a2-b1);
return c1*c2<EPS && c3*c4<EPS;
} int main(){
int n;
int kase = ;
while( scanf("%d",&n), n ){
if(kase!=) puts("");
bool flag = true;
for(int i=;i<n;i++){
double a,b;
scanf("%lf%lf",&a,&b);
pts[i] = POINT(a,b);
for(int j=;j<i-;j++){
if( SegmentProperIntersection(pts[j],pts[j+],pts[i-],pts[i])) flag = false;
}
}
for(int j=;j<n-;j++){
if( SegmentProperIntersection(pts[j],pts[j+],pts[],pts[n-])) flag = false;
}
double area = fabs(AREA(pts,n));
if( n==||n== ){
printf("Figure %d: Impossible\n",kase++);
continue;
}
if(!flag) printf("Figure %d: Impossible\n",kase++);
else printf("Figure %d: %.2f\n",kase++,area);
}
return ;
}

[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. SwitchyOmega

    SwitchyOmega下载安装地址: http://switchyomega.com/download.html GFWList.bak.txt教程 {"+GFWed":{&qu ...

  2. wap图片滚动特效_无css3 元素js脚本编写

    手机图片滑动切换,网上有很多这样的例子,但都借助于其他组件,让代码混乱的不行:还有就是用到css3里的 transform:translate(x,y);移动元素,不过发现在不支持css3的设备上马上 ...

  3. maven本地仓库

    引入某一个站点的jar包 <repositories> <repository> <id>maven.seasar.org</id> <name& ...

  4. oracle数据库数据导出和导入

    oracle的客户端里面的bin下面有两个可执行文件,名称分别为exp.exe和imp.exe. 他俩的用途就是导出和导入数据用的. 全库 导出:exp 用户名/密码@数据库名 full=y file ...

  5. 初级——程序如何打包成apk文件

    将Eclipse Android项目打包成APK文件是本文要介绍的内容,主要是来了解并学习Eclipse Android打包的内容,具体关于Eclipse Android内容的详解来看本文.Eclip ...

  6. webstorm配置nodejs,bower,git,github

    一,配置nodejs第一大步,首先安装nodejs,安装nodejs的时候,我们需要把所有的组建勾选上,然后选择add to path,这一步会自动帮我们配置环境变量,安装完成后,打开cmd,输入no ...

  7. Python 字典和列表的对比应用

    Q:将下列格式的txt文件,打印出该选手的3个最快跑步时间 james2.txt =>“James Lee,2002-3-14,2-34,3:21,2.34,2.45,3.01,2:01,2:0 ...

  8. W81安装记录

    安装Windows 8.1之前先断网!!! 在x86的WinPE环境中安装Windows 8.1 x64的方法: 1.格式化硬盘的第一主分区C盘,将x64的ISO解压到其他分区里: 2.复制ISO解压 ...

  9. CSS3字体图标

    网址:http://icomoon.io/http://iconfont.cn/  阿里巴巴字体库 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...

  10. WindowsForm通过字符串名称实例化控件

    private Control FindControl(Control control, string controlName) { Control c1; foreach (Control c in ...