BZOJ-2732 [HNOI2012] Archery

Source: Internet
Author: User

It is still turned into an inequality group, and then the half plane is cross.

#include <cstdlib> #include <cstdio> #include <cmath> #include <cstring> #include <cctype > #include <algorithm> #define REP (i, L, R) for (int i=l; i<=r; i++) #define CLR (x, C) memset (x, C, sizeof (x)) #def Ine MAXN 234567#define Double long double#define linf 1e15using namespace std;typedef long long ll;inline int read () {int x =0, f=1; Char Ch=getchar (), while (!isdigit (CH)) {if (ch== '-') f=-1; Ch=getchar ();} while (IsDigit (CH)) x=x*10+ch-' 0 ', Ch=getchar (); return x*f;} struct p{double x, y;}; struct line{p A, b; int id; double ang;} L[MAXN], A[MAXN], Q[MAXN]; P operator-(p a, p B) {return (p) {a.x-b.x, a.y-b.y};} Double operator * (p a, p b) {return a.x*b.y-a.y*b.x;} BOOL Operator < (line A, line B) {if (A.ang==b.ang) return (A.B-A.A) * (B.B-B.A) >0; return A.ang<b.ang;} int n, m, L, R, Cnt;inline double cal (double A, double b, int x) {return b/a-a*x;} P Inter (line A, line B) {double k1= (b.b-a.a) * (A.B-A.A), k2= (A.B-A.A) * (B.A-A.A), t=k2/(K1+K2); return (P) {b.a.x+t* (b.b.x-b.a.x), b.a.y+t* (B.B.Y-B.A.Y)};} BOOL Jud (line A, line B, line t) {return (Inter (A, b)-t.a) * (T.B-T.A) >0;} void HPI (int x) {int Cnt=0;rep (i, 1, m) if (l[i].id<=x) {if (L[i].ang!=a[cnt].ang) cnt++;a[cnt]=l[i];} L=1, r=0;q[++r]=a[1]; Q[++r]=a[2];rep (i, 3, CNT) {while (L<r && Jud (Q[r-1], q[r], a[i]) r--;while (l<r && Jud (q[l+1], q[l) , A[i])) l++;q[++r]=a[i];} while (L<r && Jud (Q[r-1], q[r], q[l]) r--;while (l<r && Jud (q[l+1], q[l], Q[r])) l++;} int main () {n=read (); l[++m].a= (p) {-linf,-linf}; l[m].b= (p) {linf,-linf};l[++m].a= (p) {linf,-linf}; l[m].b= (p) {Linf, Linf};l[++m].a= (P) {linf, linf}; L[m].b= (p) {-linf, linf};l[++m].a= (p) {-linf, linf}; L[m].b= (P) {-linf,-linf};rep (i, 1, n) {double x=read (), Ya=read (), Yb=read (); l[++m].a.x=-1; l[m].a.y=cal (x, ya,-1); L[m] . b.x=1; l[m].b.y=cal (x, ya, 1); l[++m].a.x=1; L[m].a.y=cal (x, YB, 1); L[m].b.x=-1; L[m].b.y=cal (x, YB,-1); l[m].id=l[m-1].id=i;} Rep (i, 1, m) l[i].ang=atan2 (L[I].B.Y-L[I].A.Y, L[I].B.X-L[I].A. x); Sort (l+1, l+m+1); int l=0, R=n;while (l<r) {int mid= (l+r) >>1;hpi (mid+1), if (r-l>1) l=mid+1; else r=mid;} printf ("%d\n", l); return 0;}

BZOJ-2732 [HNOI2012] Archery

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.