hdu 1665 That Nice Euler Circuit(欧拉定理)
输入n个点,然后从第一个点开始,依次链接点i->点i+1,最后回到第一点(输入中的点n),求得到的图形将平面分成了多少部分。
根据欧拉定理 v_num + f_num - e_num = 2可知,求出点数跟边数便能求出平面数。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<sstream>
#include<bitset>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define eps 1e-10
using namespace std; struct Point
{
double x, y;
Point (double x=0, double y=0):x(x), y(y) {}
};
typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y); }
Vector operator - (Vector A, Vector 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 a.x < b.x || (a.x == b.x && a.y < b.y);
} int dcmp(double x)
{
if(fabs(x) < eps) return 0;
return x < 0 ? -1 : 1;
} 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 Length(Vector A) { return sqrt(Dot(A, A)); }
double Angel(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }
double Area2(Vector A, Vector B, Vector C) { return Cross(B-A, C-A); } //向量逆时针旋转
Vector Rotate(Vector A, double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
} //求直线p+tv和q+tw的交点 Cross(v, w) == 0无交点
Point GetLineIntersection(Point p, Vector v, Point q, Vector w)
{
Vector u = p-q;
double t = Cross(w, u) / Cross(v, w);
return p + v*t;
} //点p到直线ab的距离
double DistanceToLine(Point p, Point a, Point b)
{
Vector v1 = b - a, v2 = p - a;
return fabs(Cross(v1, v2)) / Length(v1);//如果不带fabs 得到的是有向距离
} //点p到线段ab的距离
double DistanceToSegment(Point p, Point a, Point b)
{
if(a == b) return Length(p-a);
Vector v1 = b-a, v2 = p-a, v3 = p-b;
if(dcmp(Dot(v1, v2) < 0)) return Length(v2);
else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);
else return fabs(Cross(v1, v2)) / Length(v1);
} //点p在直线ab上的投影
Point GetLineProjection(Point p, Point a, Point b)
{
Vector v = b-a;
return a + v*(Dot(v, p-a) / Dot(v, v));
} //点段相交判定
bool SegmentItersection(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 dcmp(c1)*dcmp(c2) < 0 && dcmp(c3)*dcmp(c4) < 0;
} //点在线段上
bool OnSegment(Point p, Point a1, Point a2)
{
return dcmp(Cross(a1-p, a2-p)) == 0 && dcmp(Dot(a1-p, a2-p)) < 0;
} //多变形面积
double PolygonArea(Point* p, int n)
{
double ret = 0;
FF(i, 1, n) ret += Cross(p[i]-p[0], p[i+1]-p[0]);
return ret/2;
} Point read_point()
{
Point a;
scanf("%lf%lf", &a.x, &a.y);
return a;
} const int maxn = 301;
Point p[maxn], v[maxn*1000]; int main()
{
int n, kase = 1;
while(scanf("%d", &n), n)
{
REP(i, n)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
v[i] = p[i];
}
int cnt = n-1, e_num = n-1;//原有边数 //枚举所有边,求出相交出来的新的点
REP(i, n-1) FF(j, i+1, n-1)
if(SegmentItersection(p[i], p[i+1], p[j], p[j+1]))
v[cnt++] = GetLineIntersection(p[i], p[i+1]-p[i], p[j], p[j+1]-p[j]); sort(v, v+cnt);
int v_num = unique(v, v+cnt) - v;//去重点 REP(i, v_num) REP(j, n-1)
if(OnSegment(v[i], p[j], p[j+1])) e_num++;//线段被切割
printf("Case %d: There are %d pieces.\n", kase++, e_num + 2 - v_num);
}
return 0;
}
hdu 1665 That Nice Euler Circuit(欧拉定理)的更多相关文章
- LA 3263 That Nice Euler Circuit(欧拉定理)
That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...
- poj2284 That Nice Euler Circuit(欧拉公式)
题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...
- POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)
That Nice Euler Circuit Time Limit: 3000MS M ...
- UVALive - 3263 That Nice Euler Circuit (几何)
UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址: UVALive - 3263 That Nice Euler Circuit 题意: 给 ...
- That Nice Euler Circuit(LA3263+几何)
That Nice Euler Circuit Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu D ...
- UVALi 3263 That Nice Euler Circuit(几何)
That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...
- poj 2284 That Nice Euler Circuit 解题报告
That Nice Euler Circuit Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1975 Accepted ...
- UVa 10735 (混合图的欧拉回路) Euler Circuit
题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...
- UVA 10735 Euler Circuit 混合图的欧拉回路(最大流,fluery算法)
题意:给一个图,图中有部分是向边,部分是无向边,要求判断是否存在欧拉回路,若存在,输出路径. 分析:欧拉回路的定义是,从某个点出发,每条边经过一次之后恰好回到出发点. 无向边同样只能走一次,只是不限制 ...
随机推荐
- Java中的位运算符、移位运算
一.位运算 Java中有4个位运算,它们的运算规则如下: (1)按位与 (&) :两位全为1,结果为1,否则为0: (2)按位或 (|) :两位有一个为1,结果为1,否则为0: (3) ...
- Smarty模板Windows下写代码 放到CentOS6.5无法正确解析
如题:报错: Unable to load template file 'System/header.htm' in '/var/www/website/cms/Template/Default/We ...
- Android下调用收发短信邮件等
Android下调用收发短信邮件等 1,调web浏览器Uri myBlogUri = Uri.parse("http://xxxxx.com");returnIt = new In ...
- ZOJ 3483 简单if-else
提醒:答案要约分,不然会错! #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- 基于visual Studio2013解决C语言竞赛题之0902文件查找
题目
- JQuery EasyUI框架学习
前言 新项目的开发前端技术打算採用EasyUI框架(基于EasyUI较为丰富的UI组件库),项目组长将前端EasyUI这块的任务分配给了我.在进行开发之前,须要我这菜鸟对EasyUI框架进行一些基础的 ...
- this小记
this小记 太久没有研究底层的js相关,今晚差点被紫红爸爸上课了. 正题 var net=new Object(); //定义一个全局变量net net.AjaxRequest=function(u ...
- log4net学习目录
log4net是用来记录日志的,日志是用来帮助我们排除错误和异常的.这是我们编写软件必须要用到的东西,前面总结了一些有关日志和log4net的文章,在这整理个目录东大家参考. C#日志工具汇总 log ...
- MYSQL获取自增主键【4种方法】
通常我们在应用中对mysql执行了insert操作后,需要获取插入记录的自增主键.本文将介绍java环境下的4种方法获取insert后的记录主键auto_increment的值: 通过JDBC2.0提 ...
- c++实现atoi()和itoa()函数(字符串和整数转化)
(0) c++类型所占的字节和表示范围 c 语言里 类型转换那些事儿(补码 反码) 应届生面试准备之道 最值得学习阅读的10个C语言开源项目代码 一:起因 (1)字符串类型转化为整数型(Integer ...