Codeforces GYM 100651 D I Conduit! (水计算几何)
来源:互联网 发布:数据挖掘从应用角度 编辑:程序博客网 时间:2024/04/30 19:23
大致题意:
1e3 个线段,画在一张纸上,求可以看成多少个线段,( 两个线段部分重叠,或收尾相接将看成一个线段)
思路:
在同一一条直线上的两条线段: 他们斜率相等,他们在Y轴或X轴上的投影点相等。然后根据这两个排下序就可以搞出来了。
这题卡精度,要用到eps
//#pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <ctime>#include <bitset>#include <algorithm>#define SZ(x) ((int)(x).size())#define ALL(v) (v).begin(), (v).end()#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i)#define REP(i,n) for ( int i=1; i<=int(n); i++ )#define rep(i,n) for ( int i=0; i< int(n); i++ )using namespace std;typedef long long ll;#define X first#define Y secondtypedef pair<double,double> pii;template <class T>inline bool RD(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return 0; while (c != '-' && (c<'0' || c>'9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0'); ret *= sgn; return 1;}template <class T>inline void PT(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) PT(x / 10); putchar(x % 10 + '0');}const int N = 1e4+100;const double inf = 1e30;const double eps = 1e-6;int n;struct node{ pii u,v; double k,p;}all[N];bool d1(double x,double y) { return x > y + eps;} // x > ybool d2(double x,double y) { return x < y - eps;} // x < ybool d3(double x,double y) { return x > y - eps;} // x >= ybool d4(double x,double y) { return x < y + eps;} // x <= ybool dd(double x,double y) { return fabs( x - y ) < eps;} // x == ybool cmp(const node& a, const node& b) { if( dd(a.k , b.k) ) { if( dd( a.p , b.p ) ) { if( dd( a.u.X , b.u.X ) ) return d2( a.u.Y , b.u.Y); return d2( a.u.X , b.u.X ); } return d2( a.p, b.p) ; } return d2(a.k , b.k) ;}int main(){ while( scanf("%d",&n) && n){ REP(i,n){ scanf("%lf%lf%lf%lf",&all[i].u.X, &all[i].u.Y, &all[i].v.X, &all[i].v.Y); if( d1( all[i].u.X , all[i].v.X ) ) swap(all[i].u, all[i].v); if( dd( all[i].u.X , all[i].v.X ) ) { if( d1( all[i].u.Y , all[i].v.Y ) ) swap(all[i].u, all[i].v); all[i].k = inf; all[i].p = all[i].u.X; } else { all[i].k = ( ( all[i].u.Y - all[i].v.Y )/( all[i].u.X - all[i].v.X ) ); all[i].p = all[i].u.Y - all[i].k * all[i].u.X; } } sort(all+1,all+1+n,cmp); all[0].k = all[0].p = -inf; int ans = 0, pos = 0; double bord; REP(i,n){ if( dd( all[i].k , inf) ) { pos = i; break; } if( dd( all[i].k , all[i-1].k ) == false || dd( all[i].p , all[i-1].p ) == false ){ ans ++; bord = all[i].v.X; }else{ if( d1( all[i].u.X , bord ) ) ans ++; bord = max( bord, all[i].v.X ); } } if( pos ) { ans ++; bord = all[pos].v.Y; for(int i = pos+1; i <= n; i ++){ if( dd( all[i].p , all[i-1].p ) == false ) ans ++, bord = all[i].v.Y; else{ if( d1( all[i].u.Y , bord ) ) ans ++; bord = max( bord, all[i].v.Y ); } } } PT(ans),puts(""); }}
0 0
- Codeforces GYM 100651 D I Conduit! (水计算几何)
- Gym 101243 I Land Division[计算几何]
- CodeForces 203D Hit Ball 水!计算几何
- Codeforces Round #346 (Div. 2)(D)计算几何
- codeforces 13D. Triangles(计算几何 dp)
- Codeforces Round #445 Div1 D:Symmetric Projections (计算几何)
- Codeforces Gym-101617F Move Away [计算几何]
- GYM 100182 B.Euclid(计算几何)
- Codeforces 659D Bicycle Race【计算几何】
- Educational Codeforces Round 11 D 计算几何
- CodeForces Gym 100735I
- CodeForces Gym 100735D
- 2015年ALPC暑期专题练习I (计算几何) D Intersecting Lines
- GYM 101173 C.Convex Contour(计算几何)
- CodeForces 385 D.Bear and Floodlight(状压DP+计算几何)
- Codeforces Round #409Div.2D. Volatile Kite(计算几何)
- Codeforces 8D Two Friends 三分+二分+计算几何
- codeforces #8D Two Friends 二分答案+计算几何
- 【leetcode每日一题】203.Remove Linked List Elements
- 偏差、方差权衡
- 关于查找有关技术(如WIFI)的现状的方法
- 第54讲:Scala中复合类型实战详解学习笔记
- C与OC
- Codeforces GYM 100651 D I Conduit! (水计算几何)
- BI@Report中按钮操作
- macbook pro下安装三系统
- LIU_XF (原创)QT Creator的style sheet的几种用法(QT Creator)(StyleSheet)(样式)(QT4.7)(用法)
- Unity3D学习笔记《Roll-a-Ball》二
- C++ Primer 5e chapter 17.1
- NSURLSession的类型(断点续传,开始取消。后台运行)
- Unity_一张图看懂MonoBehaviour的生命周期
- Java实现GZIP压缩