LA3263 一笔画
题目大意:
依次给定多个点(要求第一个点和最后一个点重叠),把前后两个点相连求最后得到的图形的面的个数
根据欧拉定理:
设平面图的顶点数为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 一笔画的更多相关文章
- nyoj-一笔画问题-欧拉图+联通判定
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- fcitx 候选词出现奇怪的笔画
原来fcitx还有笔画输入的功能,输入h出现一个横,s出现竖,p是撇,n是捺,z是折. 虽然很有意思,但是不实用,而且还会出现在第一页候选词中,影响输入,可以通过配置文件禁用掉: $ vim ~/.c ...
- NYOJ 42 一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- ACM题目————一笔画问题
描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N< ...
- nyoj-----42一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...
- nyist 42 一笔画 (欧拉回路 + 并查集)
nyoj42 分析: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径. 若该路径是一个圈,则称为欧拉(Euler)回路. 具有欧拉回路的图称为欧拉图(简称E图).具有欧拉路 ...
- Nyoj42 一笔画问题 (欧拉道路)
http://acm.nyist.net/JudgeOnline/problem.php?pid=42题目链接 #include <cstdio> #include <cstring ...
- sql server 利用首字母拼音排序和笔画排序的语句
--按笔画排序 select * from Student order by Sname COLLATE Chinese_PRC_Stroke_CS_AS_KS_WS --按字母拼音排序 select ...
随机推荐
- 暴力 ZOJ 1403 Safecracker
题目传送门 /* 暴力:纯暴力,在家水水 */ #include <cstdio> #include <cstring> #include <algorithm> ...
- magento 获得当前产品页面的产品id
$product_id = Mage::registry('current_product')->getId();
- C# Equals的重写
using System; using System.Collections.Generic; using System.Text; namespace Equal { using Syste ...
- JDK集合框架--综述
接下来的几篇博客总结一下对jdk中常用集合类知识,本篇博客先整体性地介绍一下集合及其主要的api: 从整体上来说,集合分两大类collection和map: 首先来看看Collection: c ...
- Spring Cloud是什么?
[学习笔记] 3)Spring Cloud是什么?马克-to-win@马克java社区:i)Spring Cloud是一个微服务框架,Spring Cloud基于微服务基础框架Netflix进行了up ...
- iOS 画环形图
由于新项目的的需求,需要画环形图,由于以前都没接触过这一类(我是菜鸟),去cocochina山找到了一个案例,个人觉得还可以,分享一下 github 地址https://github.com/zhou ...
- .vue文件在phpstorm中红线解决办法
主要原因是js版本太低, 1,安装vue.js插件, 2,设置file type,vue.js添加 *.vue, 3,切换js版本为es6,
- android中使用图文并茂的按钮
代码: <LinearLayout android:orientation="horizontal" android:layout_width="match_par ...
- Python学习 Day 9 property 多重继承 Mixin
在绑定属性时,如果我们直接把属性暴露出去,虽然写起来很简单,但是,没办法检查参数,导致可以把成绩随便改: s = Student() s.score = 9999 为了限制score的范围,可以通过一 ...
- .net 操作xml --移除注释节点
/// <summary> /// xml字符串转xml文档 忽略注释信息 /// </summary> /// <param name="sXml" ...