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

根据欧拉定理:

设平面图的顶点数为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. 贪心 CodeForces 124B Permutations

    题目传送门 /* 贪心:全排列函数使用,更新最值 */ #include <cstdio> #include <algorithm> #include <cstring& ...

  2. 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...

  3. post和get提交服务器编码过程

    参考资料:http://blog.csdn.net/z55887/article/details/46975679 先说出一个知识点: 如果浏览器端编码是UTF-8,那在服务器端解决乱码问题的方法有两 ...

  4. IOS编译报错:objc-class-ref in AppDelegate.o之解决方案 Xcode7

    Undefined symbols for architecture x86_64: "_OBJC_CLASS_$_QQApiInterface", referenced from ...

  5. html5改良的input元素的种类

    1.url类型.email类型.date类型.time类型.datetime类型.datetime-local类型. month类型.week类型.number类型.range类型.search类型. ...

  6. npm run dev报错--Error: Cannot find module 'yargs-parser'

    Error: Cannot find module 'yargs-parser'  ---报错不知何解??? 百度了很久没找到方法,是缺少“ yargs-parser ”模块,需要安装一下即可:cnp ...

  7. XamarinAndroid 自动绑定View变量

    Android 编程时我们少不了使用FindIdByView函数,在Xamarin Android开发时也需要如此.这个工作很无聊且烦人.在常规Android开发中,人们已经发明了一些方法免除这项工作 ...

  8. @import与link方式的区别

    1. 老祖宗的差别.link属于XHTML标签,而@import完全是CSS提供的一种方式. link标签除了可以加载CSS外,还可以做很多其它的事情,比如定义RSS,定义rel连接属性等,@impo ...

  9. 在Swift中定义属于自己的运算符

    precedencegroup ChainingPrecedence { associativity: left higherThan: TernaryPrecedence } infix opera ...

  10. jQuery 首页搜索区域模块随页面滑动而变化

    /*搜索区块的颜色变化*/ function search(){ var searchBox = document.querySelector('.m_head'); var bannerBox = ...