Shanghai 2004(UVaLive 3263) - That Nice Euler Circuit
来源:互联网 发布:手游编程 编辑:程序博客网 时间:2024/06/04 19:49
Link To The Problem
Solution : 离散化,欧拉平面公式: V - E + F = 2
// Shanghai 2004 That Nice Euler Circuit// Solution : #include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>using namespace std;#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)#define oo 1e6#define eps 1e-10#define nMax 1010//{ #define pb push_back#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << x << endl#define F first#define S second#define bug puts("OOOOh.....");#define zero(x) (((x)>0?(x):-(x))<eps)#define LL long long#define DB double #define sf scanf#define pf printf#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)double const pi = acos(-1.0);double const inf = 1e9;double inline sqr(double x) { return x*x; }int dcmp(double x){ if(fabs(x)<eps) return 0; return x>0?1:-1;}#define point pair<double,double> #define x first#define y secondstruct line{point a,b;line() {};line(point a,point b):a(a),b(b){};};int n,cas=1;vector<line> l;vector<point> event,v;point a[4000];double det(point u,point v) {return u.x*v.y - u.y*v.x;}double dot(point u,point v) {return u.x*v.x + u.y*v.y;}point Mul(point u,point v){return point(u.x-v.x,u.y-v.y);}int parallel(line u,line v){return dcmp(det(Mul(u.a,u.b),Mul(v.a,v.b)))==0;}point intersection(line u,line v) {point ret = u.a;double t = det(Mul(u.a,v.a),Mul(v.a,v.b)) / det(Mul(u.a,u.b),Mul(v.a,v.b));ret.x += (u.b.x-u.a.x)*t;ret.y += (u.b.y-u.a.y)*t;return ret;}int dot_on_seg(point p,point u,point v){return dcmp(det(Mul(p,u),Mul(v,p)))==0 && dcmp(dot(Mul(p,u),Mul(p,v)))<0;}int dot_in_seg(point p,point u,point v){return dcmp(det(Mul(p,u),Mul(v,p)))==0 && dcmp(dot(Mul(p,u),Mul(p,v)))<=0;}int intersection(line u,line v,point &tmp){if(parallel(u,v)) return 0;tmp = intersection(u,v);return dot_in_seg(tmp,u.a,u.b) && dot_in_seg(tmp,v.a,v.b);//return 1;}void read(){rep(i,n) sf("%lf%lf",&a[i].F,&a[i].S);n--;l.clear();event.clear();rep(i,n) {l.pb(line(a[i],a[i+1]));event.pb(a[i]);}}int small(point u,point v) {if(dcmp(u.x-v.x)==0) return dcmp(u.y-v.y) < 0;return dcmp(u.x-v.x) < 0;}int equal(point u,point v) {return dcmp(u.x-v.x)==0 && dcmp(u.y-v.y)==0;}void sovle(){point p;//event.clear();rep(i,n) for(int j=i+1;j<n;j++){if(intersection(l[i],l[j],p)){event.pb(p);}}sort(event.begin(),event.end(),small);v.clear();point tmp = event[0];v.pb(tmp);for(int i=0;i<event.size();i++) {if(equal(tmp,event[i])) continue;tmp = event[i];v.pb(tmp);}int F=0,V=0,E=n;V = v.size();for(int i=0;i<V;i++){for(int j=0;j<n;j++){if(dot_on_seg(v[i],a[j],a[j+1])) E++;}}//dbg(V);F = E-V+2;pf("Case %d: There are %d pieces.\n",cas++,F);return ;}int main() {#ifndef ONLINE_JUDGEfreopen("in.txt","r",stdin);#endifwhile(sf("%d",&n),n){read();sovle();}return 0;}
Code :
- Shanghai 2004(UVaLive 3263) - That Nice Euler Circuit
- UVALive 3263 That Nice Euler Circuit
- UVALive 3263 That Nice Euler Circuit
- UVALive 3263 That Nice Euler Circuit
- UVALive - 3263 That Nice Euler Circuit (几何)
- UVALive - 3263 - That Nice Euler Circuit (计算几何~~)
- uvaLive 3263 That Nice Euler Circuit 欧拉定理
- UVALive 3263 That Nice Euler Circuit(计算几何)
- That Nice Euler Circuit
- LA 3263 - That Nice Euler Circuit
- UVA LIVE-3263 - That Nice Euler Circuit
- UVALive 3263 That Nice Euler Circuit 计算几何欧拉定理
- UVALive 3263 That Nice Euler Circuit 计算几何+欧拉定理
- Uvalive 3263 That Nice Euler Circuit(几何欧拉定理)
- uva1342 That Nice Euler Circuit
- HDU 1665 or UVALive 3263 || That Nice Euler Circuit (欧拉定理求面数 F = E+2-V
- LA 3263 - That Nice Euler Circuit 欧拉定理
- POJ 2284 That Nice Euler Circuit (LA 3263 HDU 1665)
- javaweb中请求转发和重定向之间区别与联系
- ora-02065
- ORA-01078 & LRM-00109
- Linux异步通知
- 计算机三级网络技术备考复习资料
- Shanghai 2004(UVaLive 3263) - That Nice Euler Circuit
- Poll机制
- Java Web开发中路径问题的总结
- 如何动态调整控件大小和隐藏控件显示
- 关于一道题的思考
- Lucene 学习资料
- php实现商品浏览记录
- GUI 主循环设计及其在 MiniGUI, GTK, QT 的实现
- Ural 1046 Geometrical Dreams