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 ...
随机推荐
- 批量远程执行linux服务器程序--基于pxpect(多进程、记日志版)
#!/usr/bin/python '''Created on 2015-06-09@author: Administrator''' import pexpect import os,sys fro ...
- nginx配置文件内容详情及基本属性配置
Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...
- html5新属性contenteditable 对于那些不可编辑的标签,现在都可以编辑了
contenteditable = true 表示该html标签的内容可以编辑,对于那些不可编辑的标签,现在都可以编辑了.
- 用到了yii2 hasMany() 方法,一对多关联
view页面代码:其中supply,item,price是一个AR类都是一个类,item和prices是一对多关系: [ 'label' => '参考', 'format' => 'htm ...
- .NET中将中文符号转换成英文符号
public static string ConvertToEn(string text) { const string s1 = ".:,?!.“”‘’"; const stri ...
- Oracle卸载之linux快速卸载rac脚本-一键卸载
#!/bin/bash#Usage:Log on as the superuser('root') on node1,node2 cd /u01/app/11.2.0/grid/bin./crsctl ...
- Python爬虫实例(五) requests+flask构建自己的电影库
目标任务:使用requests抓取电影网站信息和下载链接保存到数据库中,然后使用flask做数据展示. 爬取的网站在这里 最终效果如下: 主页: 可以进行搜索:输入水形物语 点击标题进入详情页: 爬虫 ...
- Swap---hdu2819(最大匹配)
题意:通过交换行或者列来实现对角线(左上角到右下角)上都是1, 首先,如果某行全是0或者某列全是0必然不满足情况输出-1,如果能转换的话,那么必然可以通过全由行(列)变换得到: 还有就是对角线上的N个 ...
- mysql 数据操作 单表查询 concat()函数 定义显示格式
#定义显示格式 concat() 函数用于连接字符串 类似于python 格式化操作print("姓名:%s" % name)或者 用,拼接一个一个的变量print("a ...
- CentOS7安装mysql-python模块
# sudo pip install mysql-python 此时会提示找不到mysql-config文件,我们安装一下mysql-community-devel # sudo yum instal ...