题目传送门

题意:一笔画,问该图形将平面分成多少个区域

分析:训练指南P260,欧拉定理:平面图定点数V,边数E,面数F,则V + F - E =  2。那么找出新增的点和边就可以了。用到了判断线段相交,求交点,判断点在线上

/************************************************
* Author :Running_Time
* Created Time :2015/10/22 星期四 09:10:09
* File Name :LA_3263.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 300 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
struct Point {
double x, y;
Point (double x=0, double y=0) : x (x), y (y) {}
};
typedef Point Vector;
double dot(Vector A, Vector B) {
return A.x * B.x + A.y * B.y;
}
double cross(Vector A, Vector B) {
return A.x * B.y - A.y * B.x;
}
int dcmp(double x) {
if (fabs (x) < EPS) return 0;
else return x < 0 ? -1 : 1;
}
Vector operator + (Vector A, Vector B) {
return Vector (A.x + B.x, A.y + B.y);
}
Vector operator - (Vector A, Vector B) {
return Vector (A.x - B.x, A.y - B.y);
}
Vector operator * (Vector A, double p) {
return Vector (A.x * p, A.y * p);
}
Vector operator / (Vector A, double p) {
return Vector (A.x / p, A.y / p);
}
bool operator < (const Point &a, const Point &b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
bool operator == (const Point &a, const Point &b) {
return dcmp (a.x - b.x) == 0 && dcmp (a.y - b.y) == 0;
}
double length(Vector A) {
return sqrt (dot (A, A));
}
Point point_inter(Point p, Vector V, Point q, Vector W) {
Vector U = p - q;
double t = cross (W, U) / cross (V, W);
return p + V * t;
}
Point point_proj(Point p, Point a, Point b) {
Vector V = b - a;
return a + V * (dot (V, p - a) / dot (V, V));
}
bool inter(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) * dcmp (c2) < 0 && dcmp (c3) * dcmp (c4) < 0;
}
bool on_seg(Point p, Point a1, Point a2) {
return dcmp (cross (a1 - p, a2 - p)) == 0 && dcmp (dot (a1 - p, a2 - p)) < 0;
}
Point P[N], V[N*N]; int main(void) {
int n, cas = 0;
while (scanf ("%d", &n) == 1) {
if (!n) break;
for (int i=0; i<n; ++i) {
scanf ("%lf%lf", &P[i].x, &P[i].y);
V[i] = P[i];
}
n--;
int v = n, e = n;
for (int i=0; i<n; ++i) {
for (int j=i+1; j<n; ++j) {
if (inter (P[i], P[i+1], P[j], P[j+1])) {
V[v++] = point_inter (P[i], P[i+1] - P[i], P[j], P[j+1] - P[j]);
}
}
}
sort (V, V+v);
v = unique (V, V+v) - V;
for (int i=0; i<v; ++i) {
for (int j=0; j<n; ++j) {
if (on_seg (V[i], P[j], P[j+1])) e++;
}
}
printf ("Case %d: There are %d pieces.\n", ++cas, e + 2 - v);
} return 0;
}

  

简单几何(求划分区域) LA 3263 That Nice Euler Circuit的更多相关文章

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

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

  2. UVALive - 3263 That Nice Euler Circuit (几何)

    UVALive - 3263 That Nice Euler Circuit (几何) ACM 题目地址:  UVALive - 3263 That Nice Euler Circuit 题意:  给 ...

  3. Codeforces 935 简单几何求圆心 DP快速幂求与逆元

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

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

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

  5. 简单几何(求凸包点数) POJ 1228 Grandpa's Estate

    题目传送门 题意:判断一些点的凸包能否唯一确定 分析:如果凸包边上没有其他点,那么边想象成橡皮筋,可以往外拖动,这不是唯一确定的.还有求凸包的点数<=2的情况一定不能确定. /********* ...

  6. 简单几何(求交点) UVA 11437 Triangle Fun

    题目传送门 题意:三角形三等分点连线组成的三角形面积 分析:入门题,先求三等分点,再求交点,最后求面积.还可以用梅涅劳斯定理来做 /********************************** ...

  7. 简单几何(求交点) UVA 11178 Morley's Theorem

    题目传送门 题意:莫雷定理,求三个点的坐标 分析:训练指南P259,用到了求角度,向量旋转,求射线交点 /*********************************************** ...

  8. uvalive 3263 That Nice Euler Circuit

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

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

随机推荐

  1. cnblog可以直接黏贴qq截图,但最好不要偷懒

    秋秋(qq)基本上算是ytkah本人开机后要开的软件了,平时也习惯用Ctrl+Alt+A快捷键来进行截图.很早以前ytkah一个无意间发现cnblog可以直接黏贴qq截图,当时截图后可能是忘记黏贴到其 ...

  2. Card(bestcoder #26 B)

    Card Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. 如何看K线图基础知识

    在日K线图中一般白线.黄线.紫线.绿线依次分别表示:5.10.20.60日移动平均线,但这并不是固定的,会根据设置的不同而不同,比如你也可以在系统里把它们设为5.15.30.60均线. 你看K线图的上 ...

  4. [Android教程]EditText怎样限制用户的输入?数字/字母/邮箱

    有输入必有验证.为了防止用户随便输入确保提交数据的合法性,程序不得不在文本输入框(EditText)中增加限制或验证. 关于输入类型有数字.字母.邮箱.电话等形式,这些具体得根据业务来.那么Andro ...

  5. git clone报错

    (文章是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) Could not chdir to home directory /home/wangzheng: ...

  6. 腾讯新浪通过IP地址获取当前地理位置(省份)的接口

    腾讯新浪通过IP地址获取当前地理位置(省份)的接口  腾讯的接口是 ,返回数组 http://fw.qq.com/ipaddress 返回值 var IPData = new Array(" ...

  7. PHP中冒号、endif、endwhile、endfor这些都是什么

    我们经常在wordpress一类博客程序的模板里面看到很多奇怪的PHP语法,比如:<?php if(empty($GET_['a'])): ?><font color="r ...

  8. java前三本基础知识总结

    基础软件:1:JDK,JRE,JVM(一些参数和作用),GC(机制和算法),Class,Loader(机种作用,加载顺序) 2:环境搭建:JAVA_HOME,path,class 语言基础:引用类型: ...

  9. wireshark http抓包命令行详解

    This article is a quick and easy HowTo detailing the use of Wireshark or another network sniffing pr ...

  10. 使用shadow dom封装web组件

    什么是shadow dom? 首先我们先来看看它长什么样子.在HTML5中,我们只用写如下简单的两行代码,就可以通过 <video> 标签来创建一个浏览器自带的视频播放器控件. <v ...