UVALive - 3263 That Nice Euler Circuit (几何)

ACM

题目地址: 

UVALive - 3263 That Nice Euler Circuit

题意: 

给出一个点,问连起来后的图形把平面分为几个区域。

分析: 

欧拉定理有:设平面图的顶点数、边数、面数分别V,E,F则V+F-E=2 

大白的题目,做起来还是非常有技巧的。

代码:

/*
* Author: illuz <iilluzen[at]gmail.com>
* File: LA3263.cpp
* Create Date: 2014-09-18 23:18:47
* Descripton: V+F-E=2
*/ #include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;
#define repf(i,a,b) for(int i=(a);i<=(b);i++) typedef long long ll; const int N = 310;
const double eps = 1e-8;
const double PI = acos(-1.0); int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0) return -1;
else return 1;
} struct Point {
double x, y;
Point() {}
Point(double _x, double _y) {
x = _x; y = _y;
}
Point operator -(const Point &b) const {
return Point(x - b.x, y - b.y);
} //叉积
double operator ^(const Point &b) const {
return x*b.y - y*b.x;
} //点积
double operator *(const Point &b) const {
return x*b.x + y*b.y;
}
//绕原点旋转角度B(弧度值),后x,y的变化
void transXY(double B) {
double tx = x,ty = y;
x = tx*cos(B) - ty*sin(B);
y = tx*sin(B) + ty*cos(B);
} bool operator <(const Point &b) const {
return x < b.x || (x == b.x && y < b.y);
} bool operator ==(const Point &b) const {
return x == b.x && y == b.y;
} void read() {
scanf("%lf", &x);
scanf("%lf", &y);
} void print() {
printf("debug: x = %f, y = %f\n", x, y);
}
}; struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e) {
s = _s;e = _e;
} //两直线相交求交点
//第一个值为0表示直线重合,为1表示平行,为0表示相交,为2是相交
//仅仅有第一个值为2时,交点才有意义
pair<int,Point> operator &(const Line &b)const {
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == 0) {
if(sgn((s-b.e)^(b.s-b.e)) == 0)
return make_pair(0,res);//重合
else return make_pair(1,res);//平行
}
double t = ((s-b.s)^(b.s-b.e)) / ((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(2,res);
}
}; //*两点间距离
double dist(Point a,Point b) {
return sqrt((a-b)*(a-b));
} //*推断点在线段上
bool OnSeg(Point P,Line L) {
return
sgn((L.s-P)^(L.e-P)) == 0 &&
sgn((P.x - L.s.x) * (P.x - L.e.x)) <= 0 &&
sgn((P.y - L.s.y) * (P.y - L.e.y)) <= 0;
} Point p[N], v[N*N];
Line a, b;
int c, e, n, cas; int main() {
ios_base::sync_with_stdio(0);
cas = 0;
while (scanf("%d", &n) && n) {
repf (i, 0, n - 1) {
p[i].read();
v[i] = p[i];
}
n--;
c = n;
repf (i, 0, n - 1) {
a.s = p[i];
a.e = p[i + 1];
repf (j, i + 1, n - 1) {
b.s = p[j];
b.e = p[j + 1];
pair<int,Point> t = a & b;
if (t.first == 2 && OnSeg(t.second, a) && OnSeg(t.second, b))
v[c++] = t.second;
}
}
sort(v, v + c);
c = unique(v, v + c) - v; e = n;
repf (j, 0, n - 1) {
a.s = p[j];
a.e = p[j + 1];
repf (i, 0, c - 1) {
if (p[j] == v[i] || p[j + 1] == v[i])
continue;
if (OnSeg(v[i], a))
e++;
}
}
// cout << e << c << endl;
printf("Case %d: There are %d pieces.\n", ++cas, e + 2 - c);
}
return 0;
}


版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVALive - 3263 That Nice Euler Circuit (几何)的更多相关文章

  1. UVALi 3263 That Nice Euler Circuit(几何)

    That Nice Euler Circuit [题目链接]That Nice Euler Circuit [题目类型]几何 &题解: 蓝书P260 要用欧拉定理:V+F=E+2 V是顶点数; ...

  2. uvalive 3263 That Nice Euler Circuit

    题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...

  3. UVAlive 3263 That Nice Euler Circuit(欧拉定理)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21363 [思路] 欧拉定理:V+F-E=2.则F=E-V+2. 其 ...

  4. UVALive 3263: That Nice Euler Circuit (计算几何)

    题目链接 lrj训练指南 P260 //==================================================================== // 此题只需要考虑线 ...

  5. LA 3263 That Nice Euler Circuit(欧拉定理)

    That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...

  6. 简单几何(求划分区域) LA 3263 That Nice Euler Circuit

    题目传送门 题意:一笔画,问该图形将平面分成多少个区域 分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2.那么找出新增的点和边就可以了.用到了判断线段相 ...

  7. That Nice Euler Circuit(LA3263+几何)

    That Nice Euler Circuit Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu D ...

  8. poj2284 That Nice Euler Circuit(欧拉公式)

    题目链接:poj2284 That Nice Euler Circuit 欧拉公式:如果G是一个阶为n,边数为m且含有r个区域的连通平面图,则有恒等式:n-m+r=2. 欧拉公式的推广: 对于具有k( ...

  9. POJ2284 That Nice Euler Circuit (欧拉公式)(计算几何 线段相交问题)

                                                          That Nice Euler Circuit Time Limit: 3000MS   M ...

随机推荐

  1. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  2. 从零開始学android&lt;数据存储(1)SharedPreferences属性文件.三十五.&gt;

    在android中有五种保存数据的方法.各自是: Shared Preferences Store private primitive data in key-value pairs. 相应属性的键值 ...

  3. 项目构建之maven篇:2.HelloWorld项目构建过程

    文件结构说明: 项目构建生命周期: 清理 编译 測试 打包 执行 部署 清理与编译 hello\pom.xml POM:Project Object Model,项目对象模型 pom.xml与ant的 ...

  4. 十步完全理解SQL(转)

    本文由 伯乐在线 - 水果泡腾片 翻译.未经许可,禁止转载!英文出处:Lukas Eder.欢迎加入翻译组. 很多程序员视 SQL 为洪水猛兽.SQL 是一种为数不多的声明性语言,它的运行方式完全不同 ...

  5. mac开启22port

    mac开启22port 选择System prefrence -> sharing , 将remote login打开 測试是否打开 import socket s = socket.socke ...

  6. 解决编译时出错提示: 'error: array must be initialized with a brace-enclosed initializer' 的错误

    编译出现这个错误的原因非常简单编译的标准不相同.如果用stdc90,这个就可以直接编译通过了. 下面是代码例子: ...... ] = NULL;或者 :char cmd[256] = '\0'; . ...

  7. C# WinForm多线程(一)Thread类库

    Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程.什么是进程呢?当一个程序开始运行时,它就是一个进程,进程所指包括 ...

  8. 【Linux探索之旅】第二部分第一课:终端Terminal,好戏上场

    内容简介 1.第二部分第一课:终端Terminal,好戏上场 2.第二部分第二课预告:命令行,世界尽在掌握 终端Terminal,好戏上场 随着第一部分的结束,我们进入了第二部分(小编你这好像是废话. ...

  9. sails不是内部或外部命令的解决方案

    1 安装好node 2 安装sails 打开cmd窗口,用命令 npm -g install sails 安装sails 安装完成后,用命令  sails new testProject 创建项目 会 ...

  10. schedule vs scheduleAtFixedRate

    最好的方法是在两者之间区分 timer灵感时间设定过去时间T,scheduleAtFixedRate将从T现在所有的任务中运行,schedule而该任务将只运行从现在开始计时. public clas ...