[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 ...
随机推荐
- windows中用eclipse开发Android环境搭建SDK安装异常
SDK更新时的“https://dl-ssl.google.com refused”错误 Download interrupted: hostname in certificate didn't ma ...
- web压力测试 - http_load
http_load是基于linux平台的一个性能测工具 非常小巧易用,可以用并行方式运行,来测试web服务器的性能 测试方式 (1)准备测试url vim url.txt 填写要测试的url,可以写多 ...
- 【性能诊断】七、并发场景的性能分析(windbg案例,线程阻塞)
简单整理一个测试Demo,抓取dump并验证,步骤如下: Symbol File Path:SRV*C:\Symbols*http://msdl.microsoft.com/download/symb ...
- C#动态数组ArrayList和List<T>的比较
C#中一维动态数组(即列表)分ArrayList和List<T>两种,其容量可随着我们的需要自动进行扩充 一.ArrayList类(少用) ArrayList位于System.Collec ...
- CryptoAPI与openssl RSA非对称加密解密(PKCS1 PADDING)交互
(以下代码中都只做测试用,有些地方没有释放内存...这个自己解决下) 1.RSA非对称的,首先提供一个供测试用的证书和私钥的数据 1)pem格式的证书和私钥(公私钥是对应的)的base64编码 voi ...
- java 反射机制01
// */ // ]]> java反射机制01 Table of Contents 1 反射机制 2 反射成员 2.1 java.lang.Class 2.2 Constructor 2.3 ...
- SIlverlight外包公司【技术展望】— Silverlight5.1.2最新版本发布,Silverlight 的更新从未停止。
微软发布新版Silverlight 5, 版本号5.1.20913.0 大家可以到微软网站去下载最新版本网址是 http://www.microsoft.com/getsilverlight/get- ...
- 【VNC】Ubuntu14.04LTS下安装VNC View
# apt-get install tightvncserver vnc4server gnome-panel gnome-settings-daemon metacity nautilus gnom ...
- Python之Fabric模块
Fabric是基于Python实现的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包括:命令执行.文件上传.下载及完整执行日 ...
- ADB工具 获取ROOT权限及复制文件方法
adb push d:\tm3_sqlit.db data/zouhao/tm3_sqlit.dbadb pull data/zouhao/tm3_sqlit.db d:\tm3_sqlit.db a ...