Poj 3335 rotating Scoreboard-semi-plane intersection

Source: Internet
Author: User
/* Poj 3335 rotating Scoreboard-the semi-plane intersection point is clockwise */# include <stdio. h> # include <math. h> const double EPS = 1e-8; const int n = 103; struct point {Double X, Y;} Dian [N]; inline bool mo_ee (Double X, Double Y) {double ret = x-y; If (Ret <0) ret =-ret; If (Ret <EPS) return 1; return 0;} inline bool mo_gg (Double X, double Y) {return x> Y + EPS;} // x> yinline bool mo_ll (Double X, Double Y) {return x <Y-EPS ;} // x <yinline bool mo_ge (Double X, Double Y) {return x> Y-EPS;} // x> = yinline bool mo_le (Double X, Double Y) {return x <Y + EPS;} // x <= yinline double mo_xmult (point P2, point P0, Point P1) // P1 returns a negative value on the left of P2, return positive {return (p1.x-0000x) * (p2.y-0000y)-(p2.x-0000x) * (p1.y-0000y) on the Right );} // calculate the Polygon Area Double mo_area_polygon (point * Dian, int N) {int I; point yuan; yuan. X = yuan. y = 0; double ret = 0; for (I = 0; I <n; ++ I) {RET + = mo_xmult (Dian [(I + 1) % N], yuan, Dian [I]);} return ret;} Point mo_intersection (point u1, point U2, point V1, point V2) {point ret = U1; double T = (u1.x-v1.x) * (v1.y-v2.y)-(u1.y-v1.y) * (v1.x-v2.x)/(u1.x-u2.x) * (v1.y-v2.y)-(u1.y-u2.y) * (v1.x-v2.x); ret. X + = (u2.x-u1.x) * t; ret. Y + = (u2.y-u1.y) * t; return ret ;} /////////////// // obtain the semi-plane intersection point mo_banjiao_jiao [N * 2] by the cutting method. point mo_banjiao_jiao_temp [N * 2]; void mo_banjiao_cut (point * ans, point Qian, point Hou, Int & nofdian) {int I, K; for (I = k = 0; I <nofdian; ++ I) {double A, B; A = mo_xmult (Hou, ANS [I], Qian); B = mo_xmult (Hou, ans [(I + 1) % nofdian], Qian); If (mo_ge (A, 0 )) // clockwise <= 0 {mo_banjiao_jiao_temp [k ++] = ans [I];} If (mo_ll (A * B, 0 )) {mo_banjiao_jiao_temp [k ++] = mo_intersection (Qian, Hou, ANS [I], ANS [(I + 1) % nofdian]) ;}} for (I = 0; I <K; ++ I) {ans [I] = mo_banjiao_jiao_temp [I];} nofdian = K;} int mo_banjiao (point * Dian, int N) {int I, nofdian; double area = mo_area_polygon (Dian, n); If (area <0) {point temp; int Zhong = n/2-1; for (I = 0; I <= Zhong; ++ I) {temp = Dian [I]; DIAN [I] = Dian [n-1-i]; DIAN [n-1-i] = temp ;}} nofdian = N; for (I = 0; I <n; ++ I) {mo_banjiao_jiao [I] = Dian [I] ;}for (I = 0; I <n; ++ I) {mo_banjiao_cut (mo_banjiao_jiao, Dian [I], Dian [(I + 1) % N], nofdian); If (nofdian = 0) {return nofdian ;}} return nofdian;} // int main () {int T, I, n; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 0; I <N; ++ I) {scanf ("% lf", & Dian [I]. x, & Dian [I]. y);} int ret = mo_banjiao (Dian, n); If (ret = 0) {printf ("NO \ n ");} else {printf ("Yes \ n") ;}} 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.