Codeforces GYM 100651 D I conduit! (Water calculation geometry)

Source: Internet
Author: User



Approximate test instructions:

1E3 segments, drawn on a piece of paper, to find out how many segments, (two segments overlap, or end-to-end will be treated as a line)


Ideas:

Two segments on the same line: they have the same slope, and they are equal to the projection points on the y-axis or x-axis. And then according to the two order of the sequence can be made out.

This card accuracy, to use the 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 A 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 * + (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, &AMP;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, AL                                L[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 + +, Bor                                D = all[i].v.y;                else{if (D1 (ALL[I].U.Y, bord)) ans + +;                        Bord = Max (bord, all[i].v.y);        }}}, PT (ans), puts (""); }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces GYM 100651 D I conduit! (Water calculation geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.