That Nice Euler Circuit
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 1975   Accepted: 624

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
0 0 0 1 1 1 1 0 0 0
7
1 1 1 5 2 1 2 5 5 1 3 5 1 1
0

Sample Output

Case 1: There are 2 pieces.
Case 2: There are 5 pieces.

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

————————————————————我是分割线————————————————————————

绝世好题。

大体思路简单,细节能烦死人。

改了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 解题报告的更多相关文章

  1. ●POJ 2284 That Nice Euler Circuit

    题链: http://poj.org/problem?id=2284 题解: 计算几何,平面图的欧拉定理 欧拉定理:设平面图的定点数为v,边数为e,面数为f,则有 v+f-e=2 即 f=e-v+2 ...

  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 ...

  3. pku 2284 That Nice Euler Circuit

    题意: 给你n个点第n个点保证与第0个点相交,然后求这n个点组成的图形可以把整个平面分成几个面 思路: 这里的解题关键是知道关于多面体的欧拉定理 多面体: 设v为顶点数,e为棱数,f是面数,则v-e+ ...

  4. poj 1094 Sorting It All Out 解题报告

    题目链接:http://poj.org/problem?id=1094 题目意思:给出 n 个待排序的字母 和 m 种关系,问需要读到第 几 行可以确定这些字母的排列顺序或者有矛盾的地方,又或者虽然具 ...

  5. Poj 1953 World Cup Noise之解题报告

    World Cup Noise Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 16369   Accepted: 8095 ...

  6. Poj 2081 Recaman's Sequence之解题报告

                                                                                                         ...

  7. POJ 1308 Is It A Tree? 解题报告

    Is It A Tree? Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32052   Accepted: 10876 D ...

  8. 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 ...

  9. POJ 1001 解题报告 高精度大整数乘法模版

    题目是POJ1001 Exponentiation  虽然是小数的幂 最终还是转化为大整数的乘法 这道题要考虑的边界情况比较多 做这道题的时候,我分析了 网上的两个解题报告,发现都有错误,说明OJ对于 ...

随机推荐

  1. loadrunner添加变量检查点

    LoadRunner设置登陆检查点 login() { lr_think_time(); web_url("passport2", "URL=http://test232 ...

  2. 基于Laravel开发博客应用系列 —— 使用Bower+Gulp集成前端资源

    本节我们将讨论如何将前端资源集成到项目中,包括前端资源的发布和引入.本项目将使用 Bower 和 Gulp 下载和集成jQuery.Bootstrap.Font Awesome 以及 DataTabl ...

  3. Hadoop整理五(基于Hadoop的数据仓库Hive)

    数据仓库,是为企业所有级别的决策制定过程,提供所有类型数据支持的战略集合.它是单个数据存储,出于分析性报告和决策支持目的而创建. 为需要业务智能的企业,提供指导业务流程改进.监视时间.成本.质量以及控 ...

  4. MYSQL插入不能中文的问题的解决

    这个问题是由于数据库的字符集不对的问题. 解决方法: 打开要用的数据库,输入命令 status 如果Client characterset 值为utf8,则要改为:set char set 'gbk' ...

  5. 在(Raspberry Pi)树莓派上安装NodeJS

    本文主讲如何在树莓派3B上安装node.js 环境描述1. 树莓派安装了`2016-11-25-raspbian-jessie-lite`(PS:在此版本的镜像中,默认禁用了ssh,在烧录好镜像之后, ...

  6. 安装部署VMware vSphere 5.5文档 (6-5) 安装配置vCenter

    部署VMware vSphere 5.5 实施文档 ########################################################################## ...

  7. ThinkPHP连接sqlserver,错误11001

    错误代码如下: :( 11001:[Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: 不知道这样的主机. 0:[Microsoft][ODB ...

  8. codevs 5971 打击犯罪

    5971 打击犯罪 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 某个地区有n(n<=1000)个犯罪团伙,当地警方按照他们 ...

  9. [BZOJ5287][HNOI2018]毒瘤(虚树DP)

    暴力枚举非树边取值做DP可得75. 注意到每次枚举出一个容斥状态的时候,都要做大量重复操作. 建立虚树,预处理出虚树上两点间的转移系数.也可动态DP解决. 树上倍增.动态DP.虚树DP似乎是这种问题的 ...

  10. 请你谈谈cookie的利弊

    以下均是自己理解和整理的,如果有错误请指出,谢谢O(∩_∩)O~~ 优点 极高的扩展性和可用性. 1)  数据持久性. 2)  不需要任何服务器资源.Cookie存储在客户端并在发送后由服务器读取. ...