Sgu 253. Theodore Roosevelt polar order + binary

Source: Internet
Author: User

/*
* 253. Theodore Roosevelt
* Question: Give a counter-clockwise convex bag, then give m points, and ask if at least K points exist in the convex bag.
* (Including on the boundary)
* Analysis: The O (n) inquiry method is certainly TLE, so we can use set or splay to maintain the data like dynamic convex hull.
* Preserve the polar order, and then use the cross product to determine the Polar Angle of the vertex that is asked in two minutes.

 

We can maintain a convex packet point set in polar order at all times. When we insert a pos point, we can calculate the Polar Angle of the POs, and then split the POs position.

(The Polar Angle of POS is exactly in the middle of P [I], p [I + 1 ). Then, determine whether the det (Pos, P [I + 1], p [I]) of the cross product is newly inserted in the convex hull.

*
**/

# Include <cstdio> # include <cstring> # include <set> # include <cmath> # include <iostream> # include <algorithm> using namespace STD; typedef long ll; const double EPS = 1e-8; const int x = 100005; int DCMP (Double X) {If (FABS (x) <EPS) return 0; return x> 0? 1:-1;} struct point {ll X, Y; double angle; point () {} Point (LL _ x, ll _ y): X (_ x ), Y (_ y) {} friend bool operator <(point a, point B) {return DCMP (. angle-b.angle) <0;} friend point operator-(point a, point B) {return point (. x-b.x,. y-b.y) ;}void input () {scanf ("% LLD", & X, & Y); angle = atan2 (Y, x );}}; set <point> convex; int n, m, K; ll det (point a, point B) {return. x * B. y-a.y * B. x;} ll det (point a, point B, point O) {return d Et (a-o, B-o);} Point pre (point POS) {set <point >:: iterator it = convex. lower_bound (POS); If (IT = convex. begin () return * (-- convex. end (); return * (-- it);} Point next (point POS) {set <point >:: iterator it = convex. upper_bound (POS); If (IT = convex. end () return * convex. begin (); return * it;} int CAL (point POS) {point pre = pre (POS); point next = next (pre); Return det (PRE, next, pos)> = 0;} int main () {// freopen ("sumd.txt ", "R", stdin); CIN> N> m> K; convex. clear (); point Pos; For (INT I = 0; I <n; I ++) {pos. input (); convex. insert (POS);} int ans = 0; while (M --) {pos. input (); ans + = CAL (POS); If (ANS> = k) break;} ans> = K? Puts ("yes"): puts ("no"); Return 0 ;}

 

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.