pku 2284 That Nice Euler Circuit
题意:
给你n个点第n个点保证与第0个点相交,然后求这n个点组成的图形可以把整个平面分成几个面
思路:
这里的解题关键是知道关于多面体的欧拉定理
多面体:
设v为顶点数,e为棱数,f是面数,则
v-e+f=2-2p
p为欧拉示性数,例如
p=0 的多面体叫第零类多面体
p=1 的多面体叫第一类多面体
这里满足的是零类多面体,我们只要求出该图形的 点v,边e即可。 怎么求点v呢? 两部分一部分是原来的n-1个顶点,然后是交出来的,我们只要判断线段相交求直线交点即可,然偶可能会摇头重复的交点去掉,求边的话我们只要求出一个规范相交的点肯定会增加一条边,枚举点然后判断 点是否在线段上(除了端点),然偶求解即可。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("d.out", "w", stdout)
#define ll unsigned long long
#define keyTree (chd[chd[root][1]][0]) #define M 100007
#define N 317 using namespace std; const int inf = 0x7f7f7f7f;
const int mod = ; struct Point
{
double x,y;
Point(double tx = ,double ty = ) : x(tx),y(ty){}
};
typedef Point Vtor; Vtor operator + (Vtor A,Vtor B) { return Vtor(A.x + B.x,A.y + B.y); }
Vtor operator - (Point A,Point B) { return Vtor(A.x - B.x,A.y - B.y); }
Vtor operator * (Vtor A,double p) { return Vtor(A.x*p,A.y*p); }
Vtor operator / (Vtor A,double p) { return Vtor(A.x/p,A.y/p); }
const double eps = 1e-;
int dcmp(double x) { if (fabs(x) < eps) return ; else return x > ? : -; }
bool operator < (Point A,Point B) { return A.x < B.x || (A.x == B.x && A.y < B.y); }
bool operator == (Point A,Point B) { return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ; } double Dot(Vtor A,Vtor B) { return A.x*B.x + A.y*B.y; }
double Length(Vtor A) { return sqrt(Dot(A,A)); }
double Angle(Vtor A,Vtor B) { return acos(Dot(A,B)/Length(A)/Length(B)); }
double Cross(Vtor A,Vtor B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A,Point B,Point C) { return Cross(B - A,C - A); }
Vtor Rotate(Vtor A,double rad) { return Vtor(A.x*cos(rad) - A.y*sin(rad),A.x*sin(rad) + A.y*cos(rad)); }
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ bool SegmentPI(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*c2) < && dcmp(c3*c4) < ; }
bool OnSegment(Point p,Point a1,Point a2)
{
return dcmp(Cross(a2 - p, a1 - p)) == && dcmp(Dot(a2 - p,a1 - p)) < ;
}
Point GetLineIn(Point P,Vtor v,Point Q,Vtor w)
{
Vtor u = P - Q;
double t = Cross(w,u)/Cross(v,w);
return P + v*t;
}
Point P[N],v[N*N];
int n; int main()
{ Read();
int Ei,Vi;
int cas = ;
while (~scanf("%d",&n))
{
if (!n) break;
Vi = ;
for (int i = ; i < n; ++i)
scanf("%lf%lf",&P[i].x,&P[i].y),v[Vi++] = P[i]; Ei = --n;
for (int i = ; i < n; ++i)
{
for (int j = i + ; j < n; ++j)
{
if (SegmentPI(P[i],P[i + ],P[j],P[j + ]))
{
v[Vi++] = GetLineIn(P[i],P[i + ] - P[i],P[j],P[j + ] - P[j]);
}
}
}
sort(v, v + Vi);
Vi = unique(v,v + Vi) - v;
for (int i = ; i < Vi; ++i)
{
for (int j = ; j < n; ++j)
{
if (OnSegment(v[i],P[j],P[j + ])) Ei++;
}
}
// printf("%d %d\n",Vi,Ei);
printf("Case %d: There are %d pieces.\n",cas++,Ei - Vi + );
} return ;
}
pku 2284 That Nice Euler Circuit的更多相关文章
- poj 2284 That Nice Euler Circuit 解题报告
That Nice Euler Circuit Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1975 Accepted ...
- ●POJ 2284 That Nice Euler Circuit
题链: http://poj.org/problem?id=2284 题解: 计算几何,平面图的欧拉定理 欧拉定理:设平面图的定点数为v,边数为e,面数为f,则有 v+f-e=2 即 f=e-v+2 ...
- POJ 2284 That Nice Euler Circuit (LA 3263 HDU 1665)
http://poj.org/problem?id=2284 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&a ...
- 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 ...
- UVa 10735 (混合图的欧拉回路) Euler Circuit
题意: 给出一个图,有的边是有向边,有的是无向边.试找出一条欧拉回路. 分析: 按照往常的思维,遇到混合图,我们一般会把无向边拆成两条方向相反的有向边. 但是在这里却行不通了,因为拆成两条有向边的话, ...
- UVA 10735 Euler Circuit 混合图的欧拉回路(最大流,fluery算法)
题意:给一个图,图中有部分是向边,部分是无向边,要求判断是否存在欧拉回路,若存在,输出路径. 分析:欧拉回路的定义是,从某个点出发,每条边经过一次之后恰好回到出发点. 无向边同样只能走一次,只是不限制 ...
- UVA-10735 - Euler Circuit(混合欧拉回路输出)
题意:给你一个图,有N个点,M条边,这M条边有的是单向的,有的是双向的. 问你能否找出一条欧拉回路,使得每条边都只经过一次! 分析: 下面转自别人的题解: 把该图的无向边随便定向,然后计算每个点的入度 ...
- Uva 1342 - That Nice Euler Circuit
Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...
随机推荐
- SSL安装方法一:在Windows Server 2008安装SSL证书(IIS 7.0)
购买的是GlobalSign 公司的通配符域名型SSL 大致的意思就是“通配符公用名填写*.域名.com,这个下面的所有子域名是不受数量限制的,*可以换成任意字符” 1 生成数字证书签名请求文件(CS ...
- jQuery --- 利用a标签的download属性下载文件!
最近遇到一个项目,需要有点击下载文件的功能. 由于文件格式是多种的,对于 rar / zip / rtf / doc / xlsx / jpg等. 点击下载有的是直接跳转到后进行下载,但有的是打开进行 ...
- JAVA内存构成详解
java memory = direct memory(直接内存) + jvm memory(MaxPermSize +Xmx) 1)直接内存跟堆 直接内存则是一块由程序本身管理的一块内存空间,它 ...
- [ASP.NET 大牛之路]02 - C#高级知识点概要(1) - 委托和事件
在ASP.NET MVC 小牛之路系列中,前面用了一篇文章提了一下C#的一些知识点.照此,ASP.NET MVC 大牛之路系列也先给大家普及一下C#.NET中的高级知识点.每个知识点不太会过于详细,但 ...
- Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure stylesheet 非全站https
Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure ...
- ES6基础教程(整理自阮一峰)
------------------------ECMAScript 6 简介------------------------ECMAScript 和 JavaScript 的关系是,前者是后者的规格 ...
- nginx详解之语法规则
1.location [=|~|~*|^~] /uri/ { … } location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] ...
- 用 chown 和 chmod 修改目录所属用户及权限
1.修改 tmp 目录所属用户为 root,用户组为 root chown -R root:root /tmp12.修改 tmp 目录为可写权限 chmod -R 777 /tmp
- 301-React Ext-React创建组件的三种方式及其区别
一.概述 React推出后,出于不同的原因先后出现三种定义react组件的方式,殊途同归:具体的三种方式: 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形 ...
- MySQL server has gone away With statement: INSERT INTO `students`......
mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了. 首选分析给出可能出现的 ...