[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 ...
随机推荐
- Jmeter使用
好久没有试过Jmeter了,下载个新版本试试,顺便温习一下. 1. 如何修改JMeter语言环境 在菜单栏中通过“选项”–“选择语言”选了英文后,下次登录JMeter,还是显示的中文,修改语言无效.关 ...
- Extjs4.2.1中的helloworld
ExtJS最新正式版4.2.1下载地址:http://pan.baidu.com/s/1qWNt2kk (开发api文档:https://github.com/extjs-doc-cn/ext4api ...
- 前端js上传文件 到后端接收文件
下面是前端js代码: <html> <head> <meta http-equiv="Content-Type" content="text ...
- eclipse修改工程名
直接修改工程可能会产生一些莫名其妙的问题,需遵循以下三步: 1. 右键工程:Refactor->Rename,或选中工程按F2,修改名称 2. 右键工程:Properties->Web P ...
- Angular学习(3)- 双向梆定
示例代码: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 3& ...
- Func系列1:安装配置
简介 Func是由红帽子公司以Fedora平台构建的统一网络控制器,是为解决集群管理.监控问题而设计开发的系统管理框架.它是一个能有效简化多服务多服务器系统管理工作的工具,它易于学习.使用和扩展,功能 ...
- 黄聪:解决丢失api-ms-win-crt-runtime-|1-1-0.dll的问题:vc_redist.x64
解决无法启动程序,因计算机中丢失api-ms-win-crt-runtime-|1-1-0.dll的问题 安装:Microsoft Visual C++ 2015 RC Redistributable ...
- ADO.NET(查询、属性扩展)
一.ADO.NET 融合面向对象的查询语句 1.只查询一条数据 //数据访问中的select方法 public stu select(string xuehao) { stu s = null; cm ...
- php 预定义接口
Traversable Traversable { } 作用:检测一个类是否可以使用 foreach 进行遍历的接口. php代码中不能用.只有内部的PHP类(用C写的类)才可以直接实现Travers ...
- html_
============= 博客大全: 脚本之家:http://www.jb51.net/list/list_233_104.htm 红黑联盟: http://www.2cto.com/kf/yid ...