[ZOJ 1010] Area (计算几何)
题目链接: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 (计算几何)的更多相关文章
- zoj 1010 Area【线段相交问题】
链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1010 http://acm.hust.edu.cn/vjudge/ ...
- [ZJU 1010] Area
ZOJ Problem Set - 1010 Area Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Jer ...
- POJ 1654 Area 计算几何
#include<stdio.h> #include<string.h> #include<iostream> #include<math.h> usi ...
- ZOJ 3157 Weapon --计算几何+树状数组
题意:给一些直线,问这些直线在直线x=L,x=R之间有多少个交点. 讲解见此文:http://blog.sina.com.cn/s/blog_778e7c6e0100q64a.html 首先将直线分别 ...
- zoj 1010 (线段相交判断+多边形求面积)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=10 Area Time Limit: 2 Seconds Mem ...
- 1010 Area
题目要求面积和判断非相邻边不相交.和数学和几何有关系. #include <stdio.h> #include <math.h> #define MISS 0.0000001 ...
- POJ2546 Circular Area(计算几何)
Circular Area ...
- UVa 1641 ASCII Area (计算几何,水题)
题意:给定一个矩阵,里面有一个多边形,求多边形的面积. 析:因为是在格子里,并且这个多边形是很规则的,所以所有格子不是全属于多边形就是全不属于,或者一半,并且我们可以根据"/"和“ ...
- Hdu-2892 area 计算几何 圆与凸多边形面积交
题面 题意:有一个凸多边形岛屿,然后告诉你从高空(x,y,h)投下炸弹,爆炸半径r,飞机水平速度和重力加速度,问岛屿被炸了多少 题解:算出来岛屿落地位置,再利用圆与凸多边形面积交 #include&l ...
随机推荐
- python之路之正则表达式
匹配格式^ 匹配字符串的开头$ 匹配字符串的结尾. 除了换行符外的所有字符[...] 用来表示一组字符,,单独列出:[amk]匹配'a','m'或'k'[^..] 不在[]中的字符:[^abc]匹配除 ...
- 创建对象的最好方式&最好的继承机制(代码实例)
/* 创建对象的最好方式:混合的构造函数/原型方式, *用构造函数定义对象的所有非函数属性,用原型方式定义对象的函数属性(方法) */ function People(sname){ this.nam ...
- 常见的java 错误--转
Java常见错误列表: 找不到符号(symbol) 类X是public的,应该被声明在名为X.java的文件中 缺失类.接口或枚举类型 缺失X 缺失标识符 非法的表达式开头 类型不兼容 非法的方法声明 ...
- php 同步因子的并发处理
在php中,如果处理支付时,会涉及到并发. 具体体现在同步通知支付结果和异步通知结果. 拿支付宝来说,同步通知call_back和异步通知notify是没有固定先后顺序的. 有可能notify先通知到 ...
- Hadoop常见错误解决
1. 通过命令和查看日志文件查看hadoop启动和运行情况 在NameNode端,可以通过 tail -100 /var/log/hadoop/hadoop/hadoop-hadoop-namenod ...
- VBA 按照文件类型名称打开一个文件
Application.GetOpenFilename(fileFilter, fileIndex, fileSelectTitle, button, False) fileFilter: 指定能够被 ...
- 【python】浅谈enumerate 函数
enumerate 函数用于遍历序列中的元素以及它们的坐标: >>> for i,j in enumerate(('a','b','c')): print i,j 0 a 1 b ...
- (转)用JQuery实现Fix表头表格
本文转载自:http://www.cnblogs.com/evlon/archive/2009/06/12/1502239.html 我的技术要点: 1.用两个表,其中一个是表头,另一个是表格做表体 ...
- bzoj2764 基因补全
Description 在生物课中我们学过,碱基组成了DNA(脱氧核糖核酸),他们分别可以用大写字母A,C,T,G表示,其中A总与T配对,C总与G配对.两个碱基序列能相互匹配,当且仅当它们等长,并且任 ...
- CentOS 7.0体验与之前版本的不同
RHEL7和CentOS7出来有一段时间了,拿出点时间研究下,有几个地方跟6和5系列相比改变比较大,估计不少童鞋有点不太习惯.下面简要举例说明改变比较大的要点: 一.CentOS的Services使用 ...