poj 2284 That Nice Euler Circuit 解题报告

本题探讨如何通过计数由特定机器绘制的线条来确定平面上形成的区域数量。利用欧拉定理,计算顶点、边数并求解区域个数。
That Nice Euler Circuit
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 1975 Accepted: 624

Description

Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his primary school Joey heard about the nice story of how Euler started the study about graphs. The problem in that story was - let me remind you - to draw a graph on a paper without lifting your pen, and finally return to the original position. Euler proved that you could do this if and only if the (planar) graph you created has the following two properties: (1) The graph is connected; and (2) Every vertex in the graph has even degree. 



Joey's Euler machine works exactly like this. The device consists of a pencil touching the paper, and a control center issuing a sequence of instructions. The paper can be viewed as the infinite two-dimensional plane; that means you do not need to worry about if the pencil will ever go off the boundary. 

In the beginning, the Euler machine will issue an instruction of the form (X0, Y0) which moves the pencil to some starting position (X0, Y0). Each subsequent instruction is also of the form (X', Y'), which means to move the pencil from the previous position to the new position (X', Y'), thus draw a line segment on the paper. You can be sure that the new position is different from the previous position for each instruction. At last, the Euler machine will always issue an instruction that move the pencil back to the starting position (X0, Y0). In addition, the Euler machine will definitely not draw any lines that overlay other lines already drawn. However, the lines may intersect. 

After all the instructions are issued, there will be a nice picture on Joey's paper. You see, since the pencil is never lifted from the paper, the picture can be viewed as an Euler circuit. 

Your job is to count how many pieces (connected areas) are created on the paper by those lines drawn by Euler. 

Input

There are no more than 25 test cases. Ease case starts with a line containing an integer N >= 4, which is the number of instructions in the test case. The following N pairs of integers give the instructions and appear on a single line separated by single spaces. The first pair is the first instruction that gives the coordinates of the starting position. You may assume there are no more than 300 instructions in each test case, and all the integer coordinates are in the range (-300, 300). The input is terminated when N is 0.

Output

For each test case there will be one output line in the format 

Case x: There are w pieces., 

where x is the serial number starting from 1. 

Note: The figures below illustrate the two sample input cases. 

Sample Input

5
0 0 0 1 1 1 1 0 0 0
7
1 1 1 5 2 1 2 5 5 1 3 5 1 1
0

Sample Output

Case 1: There are 2 pieces.
Case 2: There are 5 pieces.

Source

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

————————————————————我是分割线————————————————————————

绝世好题。

大体思路简单,细节能烦死人。

改了2天,看着题解才写出几个函数。55555........

本题根据平面图的欧拉定理求解区域个数r。

顶点个数:两两线段求交点,每个交点都是图中的顶点。

边数:在求交点时判断每个交点落在几条边上,若一个交点落在某条边上,则将这条边分裂成两条边,边数++。

之后运用欧拉定理求区域个数即可。

最后减的时候,把n处理成了点数,错的离谱......

 

  1 /*
  2     Problem:poj 2284
  3     OJ:     POJ
  4     User:   S.B.S.
  5     Time:   454 ms
  6     Memory: 3548 kb 
  7     Length: 2643 b 
  8 */
  9 #include<iostream>
 10 #include<cstdio>
 11 #include<cstring>
 12 #include<cmath>
 13 #include<algorithm>
 14 #include<queue>
 15 #include<cstdlib>
 16 #include<iomanip>
 17 #include<cassert>
 18 #include<climits>
 19 #include<vector>
 20 #include<list>
 21 #include<map>
 22 #define maxn 90001
 23 #define F(i,j,k) for(int i=j;i<k;i++)
 24 #define M(a,b) memset(a,b,sizeof(a))
 25 #define FF(i,j,k) for(int i=j;i>=k;i--)
 26 #define inf 0x7fffffff
 27 #define maxm 2016
 28 #define mod 1000000007
 29 #define eps 1e-10
 30 //#define LOCAL
 31 using namespace std;
 32 int read(){
 33     int x=0,f=1;char ch=getchar();
 34     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
 35     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
 36     return x*f;
 37 }
 38 int n,m;
 39 struct POINT //
 40 {
 41     double x;
 42     double y;
 43     POINT(double a=0,double b=0){x=a;y=b;}
 44 };
 45 struct EDGE //线段 
 46 {
 47     POINT u;
 48     POINT v;
 49     EDGE(POINT A,POINT B) {u=A;v=B;}
 50 };
 51 struct LINE //直线 
 52 {
 53     double a;
 54     double b;
 55     double c;
 56 };
 57 bool operator < (POINT A,POINT B)
 58 {
 59     return A.x<B.x || A.x==B.x && A.y<B.y;
 60 }
 61 bool operator == (POINT a,POINT b)
 62 {
 63     return abs(a.x-b.x)<eps && abs(a.y-b.y)<eps;
 64 }
 65 bool online(EDGE a,POINT b)
 66 {
 67     return abs((a.v.x-a.u.x)*(b.y-a.u.y)-(b.x-a.u.x)*(a.v.y-a.u.y))<eps && (b.x-a.u.x)*(b.x-a.v.x)<eps && (b.y-a.u.y)*(b.y-a.v.y)<eps;
 68 }
 69 LINE makeline(POINT a,POINT b)
 70 {//将线段延长成直线 
 71     LINE l;
 72     l.a=(b.y>a.y) ? b.y-a.y : a.y-b.y;                //y方向差值 
 73     l.b=(b.y>a.y) ? a.x-b.x : b.x-a.x;                //x方向差值 
 74     l.c=(b.y>a.y) ? a.y*b.x-a.x*b.y : a.x*b.y-a.y*b.x;//与水平线夹角 
 75     return l;    //返回直线 
 76 }
 77 bool lcross(LINE a,LINE b,POINT &p)
 78 {//判断直线是否相交 
 79     double d=a.a*b.b-b.a*a.b;
 80     if(abs(d)<eps) return false;
 81     //求交点 
 82     p.x=(b.c*a.b-a.c*b.b)/d;
 83     p.y=(b.a*a.c-a.a*b.c)/d;
 84     return true;
 85 }
 86 bool ecross(EDGE a,EDGE b,POINT &p)
 87 {
 88     LINE l1,l2;
 89     l1=makeline(a.u,a.v);
 90     l2=makeline(b.u,b.v);
 91     if(lcross(l1,l2,p)) return online(a,p) && online(b,p);
 92     else return false; 
 93 }
 94 POINT p[maxn],in[maxn];
 95 int cur,cnt,ans;
 96 int main()
 97 {
 98     std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
 99     #ifdef LOCAL
100     freopen("data.in","r",stdin);
101     freopen("data.out","w",stdout);
102     #endif
103     int t=0;
104     while(cin>>n&&n)
105     {
106         t++;m=cur=0;
107         for(int i=0;i<n;i++) cin>>p[i].x>>p[i].y;
108         for(int i=0;i<n;i++)
109          for(int j=0;j<n;j++){
110             EDGE l1(p[i],p[(i+1)%n]),l2(p[j],p[(j+1)%n]);
111             POINT pp;
112             if(ecross(l1,l2,pp)) in[cur++]=pp;
113         }
114         sort(in,in+cur);
115         cur=unique(in,in+cur)-in;
116         for(int i=0;i<cur;i++)
117          for(int j=0;j<n;j++){
118             EDGE ll(p[j],p[(j+1)%n]);
119             if(online(ll,in[i]) && !(ll.u==in[i])) m++;
120         }
121         cout<<"Case "<<t<<": There are "<<2+m-cur<<" pieces."<<endl;
122     }
123     return 0;
124 }
poj 2284

 

【最优潮流】直流最优潮流(OPF)课设(Matlab代码实现)内容概要:本文档主要围绕“直流最优潮流(OPF)课设”的Matlab代码实现展开,属于电力系统优化领域的教学与科研实践内容。文档介绍了通过Matlab进行电力系统最优潮流计算的基本原理与编程实现方法,重点聚焦于直流最优潮流模型的构建与求解过程,适用于课程设计或科研入门实践。文中提及使用YALMIP等优化工具包进行建模,并提供了相关资源下载链接,便于读者复现与学习。此外,文档还列举了大量与电力系统、智能优化算法、机器学习、路径规划等相关的Matlab仿真案例,体现出其服务于科研仿真辅导的综合性平台性质。; 适合人群:电气工程、自动化、电力系统及相关专业的本科生、研究生,以及从事电力系统优化、智能算法应用研究的科研人员。; 使用场景及目标:①掌握直流最优潮流的基本原理与Matlab实现方法;②完成课程设计或科研项目中的电力系统优化任务;③借助提供的丰富案例资源,拓展在智能优化、状态估计、微电网调度等方向的研究思路与技术手段。; 阅读建议:建议读者结合文档中提供的网盘资源,下载完整代码与工具包,边学习理论边动手实践。重点关注YALMIP工具的使用方法,并通过复现文中提到的多个案例,加深对电力系统优化问题建模与求解的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值