UVALive - 3263 That Nice Euler Circuit (几何 蓝书)

转载 2018年04月15日 18:14:55
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const double ep=1e-10;
const int maxn=3e2+10;

struct Point {
	double x, y;
	Point(){}
	Point(double x, double y): x(x), y(y){}
	bool operator < (const Point A) const{ return x<A.x || (x==A.x&&y<A.y);}
	
};
typedef Point Vector;

int dcmp(double x){
	if(fabs(x) < ep) return 0; else return x<0? -1 : 1;
}

Point operator + (Point A, Vector B) { return Point(A.x+B.x, A.y+B.y); }
Point operator - (Point A, Point B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (Vector A, double p) {return Vector(A.x/p, A.y/p); }
bool operator == (const Point &A, const Point &B) { return (dcmp(A.x-B.x)==0 && dcmp(A.y-B.y)==0); }
double Dot(Vector A, Vector B){ return A.x*B.x+A.y*B.y; }
double Cross(Vector A, Vector B){ return A.x*B.y-A.y*B.x; }

bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2){
	double c1=Cross(a2-a1, b1-a1), c2=Cross(a2-a1, b2-a1);
	double c3=Cross(b2-b1, a1-b1), c4=Cross(b2-b1, a2-b1);
	return dcmp(c1)*dcmp(c2)<0 && dcmp(c3)*dcmp(c4)<0;
}

Point GetLineIntersection(Point a1, Vector v1, Point a2, Vector v2){
	Vector v=a1-a2;
	double t=Cross(v2, v)/Cross(v1, v2);
	return a1+v1*t;
}

bool OnSegment(Point p, Point a, Point b){
	return dcmp(Cross(a-p, b-p))==0 && dcmp(Dot(a-p, b-p))<0;
}

int main() {
	int n, cas=0;
	Point  p[maxn], v[maxn*maxn];
	while(~scanf("%d", &n) && n) {
		for(int i=0; i<n; i++)
		{
			scanf("%lf%lf", &p[i].x, &p[i].y);
			v[i]=p[i];
		}
		n--;	
		int c=n, e=n;
		
		for(int i=0; i<n; i++)
			for(int j=i+1; j<n; j++)
				if(SegmentProperIntersection(p[i], p[i+1], p[j], p[j+1]))
					v[c++]=GetLineIntersection(p[i], p[i+1]-p[i], p[j], p[j+1]-p[j]);
		
		sort(v, v+c);
		c=unique(v, v+c)-v;//一定要加上原先的点再去重,因为原先的的端点可能落在原先的线段上,当再有边穿过时,并没有产生新边。
		for(int i=0; i<c; i++)
			for(int j=0; j<n; j++)
				if(OnSegment(v[i], p[j], p[j+1])) e++;
		
		printf("Case %d: There are %d pieces.\n", ++cas, 2+e-c);
	}
	return 0;
}

EXIF格式分析及通过XML处理(2)

 EXIF格式分析及通过XML处理 猛禽[Mental Studio](个人专栏)(BLOG)http://mental.mentsu.com 起始长度(Bytes)内容0x002Number of ...
  • Raptor
  • Raptor
  • 2004-05-09 11:09:00
  • 3258

UVALive - 3263 - That Nice Euler Circuit (计算几何~~)

UVALive - 3263 That Nice Euler Circuit Time Limit: 3000MS   Memory Limit: Unknown   ...
  • u014355480
  • u014355480
  • 2015-02-07 20:00:00
  • 585

UVALive - 3263 That Nice Euler Circuit (几何)

UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址:  UVALive - 3263 That Nice Euler Circuit...
  • hcbbt
  • hcbbt
  • 2014-09-19 20:04:27
  • 1617

平面上欧拉定理:poj 2284( LA 3263 ) That Nice Euler Circuit

3263 - That Nice Euler Circuit                                                                      ...
  • u012717411
  • u012717411
  • 2015-02-28 14:52:17
  • 623

UVALive 3263 That Nice Euler Circuit

不知道这段代码为什么错#include using namespace std; #define fi first #define se second #define pb push_back #de...
  • qq_32707623
  • qq_32707623
  • 2017-08-09 12:36:18
  • 65

UVALive 3263 That Nice Euler Circuit

题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此图案是一条闭合曲线。组成一笔画的线段可以相交,但是不会部分重叠,给出各个顶点的坐标,求这些线段将平面分成多少部分(包括封闭区...
  • acm_xx
  • acm_xx
  • 2017-10-31 17:46:05
  • 37

UVALive 3263 That Nice Euler Circuit

给出一个点的序列,按顺序做yibi
  • yanglei040
  • yanglei040
  • 2014-04-07 18:53:16
  • 394

UVA LIVE-3263 - That Nice Euler Circuit

画一个顶点为偶数的封闭的二维图,当然,这个图可以自交,给出画的过程中的一些轨迹点,求出这个图把二次元分成了几部分,例如三角形把二次元分成了两部分。 这个的话,有图中顶点数+部分数-棱数=2的定律,...
  • chaoweilanmao
  • chaoweilanmao
  • 2014-09-19 17:47:49
  • 909

UVALive 3263 That Nice Euler Circuit(计算几何)

vj的地址 好看的一笔画 让求闭合曲线形成的图形将整个平面分成了几步分。 利用到了欧拉定理:n - m + r = 2; 平面数为r = 2 - n + m 顶点数n 和 边数m 的求法...
  • huatian5
  • huatian5
  • 2016-08-11 22:26:22
  • 326

Shanghai 2004(UVaLive 3263) - That Nice Euler Circuit

Link To The Problem Solution : 离散化,欧拉平面公式: V - E + F = 2 // Shanghai 2004 That Nice Euler Ci...
  • utoppia
  • utoppia
  • 2013-10-22 01:09:37
  • 705
收藏助手
不良信息举报
您举报文章:UVALive - 3263 That Nice Euler Circuit (几何 蓝书)
举报原因:
原因补充:

(最多只允许输入30个字)