题目大意:
依次给定多个点(要求第一个点和最后一个点重叠),把前后两个点相连求最后得到的图形的面的个数

根据欧拉定理:

设平面图的顶点数为V,边数为E,面数为F,则V+F-E = 2

这里的E是指如果一条直线上被多个点分割,那么就算多条边

所以我们要求出V和E的值

先求点,已给定的点数,还要包括相连过程中相交得到的点,经过去重得到最后的点数

for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                //if(i==j) continue;
                if(onIntersection(po[i],po[i+1],po[j],po[j+1])){
                    vp.push_back(getLineIntersection(po[i],po[i+1]-po[i],po[j],po[j+1]-po[j]));
                }
            }
        }
        sort(vp.begin(),vp.end());
        c=unique(vp.begin(),vp.end()) - vp.begin(); //去重前要先进行排序,unique是对地址进行操作,所以这里使用数组也可以

然后找边,根据是否有新得到的点出现在边上,若有,每次边数++;

for(int i=0;i<c;i++){
            for(int j=0;j<n;j++){
                if(onSegment(vp[i],po[j],po[j+1]))
                    e++;
            }
        }

 #include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define eps 1e-10
struct Point {
double x,y;
Point(double x=,double y=):x(x),y(y){}
}po[];
typedef Point Vector; vector<Point> vp; int dcmp(double x)
{
if(abs(x)<eps) return ;
return x>?:-;
} bool operator==(const Point &a,const Point &b){
return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ;
} Vector operator-(Point a,Point 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 b){
return Vector(a.x*b,a.y*b);
} Vector operator/(Vector a,double b){
return Vector(a.x/b,a.y/b);
} bool operator<(const Point &a,const Point &b){
return a.x<b.x||(a.x==b.x&&a.y<b.y);
} 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;
} double Length(Vector a){
return sqrt(Dot(a,a));
} double Angle(Vector a,Vector b){
return acos(Dot(a,b) / Length(a) / Length(b));
} Point getLineIntersection(Point a,Vector va , Point b , Vector vb){
Vector c = a-b;
double t = Cross(vb,c) / Cross(va,vb);
return a+va*t;
} bool onSegment(Point a,Point st,Point la){
return dcmp(Cross(st-a,la-a)) == && dcmp(Dot(st-a,la-a)) < ;
} bool onIntersection(Point a , Point b , Point c , Point d){
double t1 = dcmp(Cross(b-a , c-a)) , t2 = dcmp(Cross(b-a , d-a));
double t3 = dcmp(Cross(d-c , b-c)) , t4 = dcmp(Cross(d-c , a-c));
return t1*t2 < && t3*t4<;
} int main()
{
// freopen("test.in","rb",stdin);
int kase = ;
int n,x,y,e,c;
while(~scanf("%d",&n)){
if(n==) break; vp.clear();
for(int i=;i<n;i++){
scanf("%d%d",&x,&y);
po[i].x = x,po[i].y = y;
vp.push_back(po[i]);
}
n--;
e=n;
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
//if(i==j) continue;
if(onIntersection(po[i],po[i+],po[j],po[j+])){
vp.push_back(getLineIntersection(po[i],po[i+]-po[i],po[j],po[j+]-po[j]));
}
}
}
sort(vp.begin(),vp.end());
c=unique(vp.begin(),vp.end()) - vp.begin();
for(int i=;i<c;i++){
for(int j=;j<n;j++){
if(onSegment(vp[i],po[j],po[j+]))
e++;
}
}
printf("Case %d: There are %d pieces.\n",++kase,e-c+);
}
return ;
}

LA3263 一笔画的更多相关文章

  1. nyoj-一笔画问题-欧拉图+联通判定

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  2. fcitx 候选词出现奇怪的笔画

    原来fcitx还有笔画输入的功能,输入h出现一个横,s出现竖,p是撇,n是捺,z是折. 虽然很有意思,但是不实用,而且还会出现在第一页候选词中,影响输入,可以通过配置文件禁用掉: $ vim ~/.c ...

  3. NYOJ 42 一笔画问题

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  4. ACM题目————一笔画问题

    描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N< ...

  5. nyoj-----42一笔画问题

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  6. UVA 291 The House Of Santa Claus (DFS求一笔画)

    题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...

  7. nyist 42 一笔画 (欧拉回路 + 并查集)

    nyoj42 分析: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径. 若该路径是一个圈,则称为欧拉(Euler)回路. 具有欧拉回路的图称为欧拉图(简称E图).具有欧拉路 ...

  8. Nyoj42 一笔画问题 (欧拉道路)

    http://acm.nyist.net/JudgeOnline/problem.php?pid=42题目链接 #include <cstdio> #include <cstring ...

  9. sql server 利用首字母拼音排序和笔画排序的语句

    --按笔画排序 select * from Student order by Sname COLLATE Chinese_PRC_Stroke_CS_AS_KS_WS --按字母拼音排序 select ...

随机推荐

  1. 题解报告:hdu 1203 I NEED A OFFER!(01背包)

    Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定的申请费用 ...

  2. 题解报告:hdu 1220 Cube

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1220 问题描述 Cowl擅长解决数学问题. 有一天,一位朋友问他这样一个问题:给你一个边长为N的立方体 ...

  3. 221 Maximal Square 最大正方形

    在一个由0和1组成的二维矩阵内,寻找只包含1的最大正方形,并返回其面积.例如,给出如下矩阵:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0返回 4. 详见:https://l ...

  4. 从0开始的hbase

    2016马上要结束了,回顾一下这一年对hbase的学习历程. 1,年初hbase的状态 使用场景:主要是用来存储业务线的mysql表,增量同步到hbase,然后每天晚上全量导入hdfs做离线计算. h ...

  5. Asp.Net中调用存储过程并返回输出参数

    /// <summary> /// 调用存储过程返回参数 /// </summary> /// <param name="orderId">&l ...

  6. java debug源码完整版

    第一步:现在myeclipse或者eclipse中下载jad插件,将class文件翻译成java文件 点击下载安装 第二步:创建一个java工程,导出成jar包.jdk自带的jar包不包含debug ...

  7. 【C++】模板简述(四):模板为什么不支持分离编译?

    上文简述了类模板相关功能,本文主要简述为什么模板不支持分离编译? 在C++中,为了一个项目的规范,我们通常把代码归为三类:声明文件.实现文件.测试文件. 比如,我要用C++实现一个链表,那么就会创建这 ...

  8. github——团队合作

  9. mac webstrom 安装less

    1.检验电脑是否安装less lessc -v 2.如果没有执行全局安装命令 npm install -g less 3.webstrom -> Preferencs-> File Wat ...

  10. [转载]iTOP-4418开发板Ubuntu系统烧写方法分享

    本文转自迅为论坛:http://topeetboard.com 开发平台:iTOP-4418开发板系统:Ubuntu 1. TF卡读写速度测试烧写 Ubuntu 对于 TF 卡的要求比较高,很多老旧的 ...