poj 2284 That Nice Euler Circuit 解题报告
|
That Nice Euler Circuit
Description Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his primary school Joey heard about the nice story of how Euler started the study about graphs. The problem in that story was - let me remind you - to draw a graph on a paper without lifting your pen, and finally return to the original position. Euler proved that you could do this if and only if the (planar) graph you created has the following two properties: (1) The graph is connected; and (2) Every vertex in the graph has even degree.
Joey's Euler machine works exactly like this. The device consists of a pencil touching the paper, and a control center issuing a sequence of instructions. The paper can be viewed as the infinite two-dimensional plane; that means you do not need to worry about if the pencil will ever go off the boundary. In the beginning, the Euler machine will issue an instruction of the form (X0, Y0) which moves the pencil to some starting position (X0, Y0). Each subsequent instruction is also of the form (X', Y'), which means to move the pencil from the previous position to the new position (X', Y'), thus draw a line segment on the paper. You can be sure that the new position is different from the previous position for each instruction. At last, the Euler machine will always issue an instruction that move the pencil back to the starting position (X0, Y0). In addition, the Euler machine will definitely not draw any lines that overlay other lines already drawn. However, the lines may intersect. After all the instructions are issued, there will be a nice picture on Joey's paper. You see, since the pencil is never lifted from the paper, the picture can be viewed as an Euler circuit. Your job is to count how many pieces (connected areas) are created on the paper by those lines drawn by Euler. Input There are no more than 25 test cases. Ease case starts with a line containing an integer N >= 4, which is the number of instructions in the test case. The following N pairs of integers give the instructions and appear on a single line separated by single spaces. The first pair is the first instruction that gives the coordinates of the starting position. You may assume there are no more than 300 instructions in each test case, and all the integer coordinates are in the range (-300, 300). The input is terminated when N is 0.
Output For each test case there will be one output line in the format
Case x: There are w pieces., where x is the serial number starting from 1. Note: The figures below illustrate the two sample input cases. Sample Input 5 Sample Output Case 1: There are 2 pieces. Source |
[Submit] [Go Back] [Status] [Discuss]
————————————————————我是分割线————————————————————————
绝世好题。
大体思路简单,细节能烦死人。
改了2天,看着题解才写出几个函数。55555........
本题根据平面图的欧拉定理求解区域个数r。
顶点个数:两两线段求交点,每个交点都是图中的顶点。
边数:在求交点时判断每个交点落在几条边上,若一个交点落在某条边上,则将这条边分裂成两条边,边数++。
之后运用欧拉定理求区域个数即可。
最后减的时候,把n处理成了点数,错的离谱......
/*
Problem:poj 2284
OJ: POJ
User: S.B.S.
Time: 454 ms
Memory: 3548 kb
Length: 2643 b
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<vector>
#include<list>
#include<map>
#define maxn 90001
#define F(i,j,k) for(int i=j;i<k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x7fffffff
#define maxm 2016
#define mod 1000000007
#define eps 1e-10
//#define LOCAL
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m;
struct POINT //点
{
double x;
double y;
POINT(double a=,double b=){x=a;y=b;}
};
struct EDGE //线段
{
POINT u;
POINT v;
EDGE(POINT A,POINT B) {u=A;v=B;}
};
struct LINE //直线
{
double a;
double b;
double c;
};
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 abs(a.x-b.x)<eps && abs(a.y-b.y)<eps;
}
bool online(EDGE a,POINT b)
{
return abs((a.v.x-a.u.x)*(b.y-a.u.y)-(b.x-a.u.x)*(a.v.y-a.u.y))<eps && (b.x-a.u.x)*(b.x-a.v.x)<eps && (b.y-a.u.y)*(b.y-a.v.y)<eps;
}
LINE makeline(POINT a,POINT b)
{//将线段延长成直线
LINE l;
l.a=(b.y>a.y) ? b.y-a.y : a.y-b.y; //y方向差值
l.b=(b.y>a.y) ? a.x-b.x : b.x-a.x; //x方向差值
l.c=(b.y>a.y) ? a.y*b.x-a.x*b.y : a.x*b.y-a.y*b.x;//与水平线夹角
return l; //返回直线
}
bool lcross(LINE a,LINE b,POINT &p)
{//判断直线是否相交
double d=a.a*b.b-b.a*a.b;
if(abs(d)<eps) return false;
//求交点
p.x=(b.c*a.b-a.c*b.b)/d;
p.y=(b.a*a.c-a.a*b.c)/d;
return true;
}
bool ecross(EDGE a,EDGE b,POINT &p)
{
LINE l1,l2;
l1=makeline(a.u,a.v);
l2=makeline(b.u,b.v);
if(lcross(l1,l2,p)) return online(a,p) && online(b,p);
else return false;
}
POINT p[maxn],in[maxn];
int cur,cnt,ans;
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
int t=;
while(cin>>n&&n)
{
t++;m=cur=;
for(int i=;i<n;i++) cin>>p[i].x>>p[i].y;
for(int i=;i<n;i++)
for(int j=;j<n;j++){
EDGE l1(p[i],p[(i+)%n]),l2(p[j],p[(j+)%n]);
POINT pp;
if(ecross(l1,l2,pp)) in[cur++]=pp;
}
sort(in,in+cur);
cur=unique(in,in+cur)-in;
for(int i=;i<cur;i++)
for(int j=;j<n;j++){
EDGE ll(p[j],p[(j+)%n]);
if(online(ll,in[i]) && !(ll.u==in[i])) m++;
}
cout<<"Case "<<t<<": There are "<<+m-cur<<" pieces."<<endl;
}
return ;
}
poj 2284
poj 2284 That Nice Euler Circuit 解题报告的更多相关文章
- ●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 ...
- pku 2284 That Nice Euler Circuit
题意: 给你n个点第n个点保证与第0个点相交,然后求这n个点组成的图形可以把整个平面分成几个面 思路: 这里的解题关键是知道关于多面体的欧拉定理 多面体: 设v为顶点数,e为棱数,f是面数,则v-e+ ...
- poj 1094 Sorting It All Out 解题报告
题目链接:http://poj.org/problem?id=1094 题目意思:给出 n 个待排序的字母 和 m 种关系,问需要读到第 几 行可以确定这些字母的排列顺序或者有矛盾的地方,又或者虽然具 ...
- Poj 1953 World Cup Noise之解题报告
World Cup Noise Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16369 Accepted: 8095 ...
- Poj 2081 Recaman's Sequence之解题报告
...
- POJ 1308 Is It A Tree? 解题报告
Is It A Tree? Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32052 Accepted: 10876 D ...
- POJ 1958 Strange Towers of Hanoi 解题报告
Strange Towers of Hanoi 大体意思是要求\(n\)盘4的的hanoi tower问题. 总所周知,\(n\)盘3塔有递推公式\(d[i]=dp[i-1]*2+1\) 令\(f[i ...
- POJ 1001 解题报告 高精度大整数乘法模版
题目是POJ1001 Exponentiation 虽然是小数的幂 最终还是转化为大整数的乘法 这道题要考虑的边界情况比较多 做这道题的时候,我分析了 网上的两个解题报告,发现都有错误,说明OJ对于 ...
随机推荐
- SQL Server 跨服务器快速数据转移
最近遇到一个问题,要将 a 服务器上的 A 库,迁移到 b 服务器上的 B 库,两个库的数据结构是一样的,但是数据库版本是 a 比 b 高,通过 sqlserver 还原这条路是走不通了,那难道除了 ...
- Spring单例 和 Scope注解
关键字 @Scope @Qualifier Singleton 单例 Spring是单例模式.结合Springboot的例子. Controller @Autowired private Tes ...
- Python面向对象中super用法与MRO机制
1. 引言 最近在研究django rest_framework的源码,老是遇到super,搞得一团蒙,多番查看各路大神博客,总算明白了一点,今天做一点总结. 2. 为什么要用super 1)让代码维 ...
- 关于Python Profilers性能分析器
1. 介绍性能分析器 作者:btchenguang profiler是一个程序,用来描述运行时的程序性能,并且从不同方面提供统计数据加以表述.Python中含有3个模块提供这样的功能,分别是cProf ...
- C# 复制、粘贴文本信息到系统剪贴板
复制: Clipboard.SetDataObject(textBox1.SelectedText); 粘贴: IDataObject iData = Clipboard.GetDataObject( ...
- bzoj1402 Ticket to Ride 斯坦纳树 + 状压dp
给定\(n\)个点,\(m\)条边的带权无向图 选出一些边,使得\(4\)对点之间可达,询问权值最小为多少 \(n \leqslant 30, m \leqslant 1000\) 首先看数据范围,\ ...
- BZOJ.2527.[POI2011]MET-Meteors(整体二分)
题目链接 BZOJ 洛谷 每个国家的答案可以二分+求前缀和,于是可以想到整体二分. 在每次Solve()中要更新所有国家得到的值,不同位置的空间站对应不同国家比较麻烦. 注意到每次Solve()其国家 ...
- 【搜索+DP】codevs1066-引水入城
[题目大意] 一个N行M列的矩形,如上图所示,其中每个格子都代表一座城 市,每座城市都有一个海拔高度.现在要在某些城市建造水利设施.水利设施有两种,分别为蓄水厂和输水站.蓄水厂的功能是利用水泵将湖泊中 ...
- 汇编代码中db,dw,dd的区别
db定义字节类型变量,一个字节数据占1个字节单元,读完一个,偏移量加1 dw定义字类型变量,一个字数据占2个字节单元,读完一个,偏移量加2 dd定义双字类型变量,一个双字数据占4个字节单元,读完一个, ...
- 【BZOJ】3195: [Jxoi2012]奇怪的道路【状压/奇偶性】【思路】
3195: [Jxoi2012]奇怪的道路 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 802 Solved: 529[Submit][Statu ...



