Hrbustoj 1291 points in a convex polygon

Source: Internet
Author: User

Question link: http://acm.hrbust.edu.cn/index.php? M = problemset & A = showproblem & problem_id = 1291.

Analysis: because it is a convex polygon, you only need to calculate the cross product for each edge.

VectorPAndQThen their Cross ProductPXQIt has the following properties:

1.PXQ> 0PInQClockwise direction;

2.PXQ<0, thenPInQIn a counter-clockwise direction;

3.PXQ= 0, thenPAndQCollinearity, which may be the same direction or reverse direction;

 

# Include <iostream> # include <string> # include <cstring> # include <algorithm> # include <cstdio> # include <cmath> # include <iomanip> using namespace STD; const int maxn = 100000; struct point {int X, Y; void read () {CIN> x> Y ;}rt, F [maxn]; double Cross (point P0, Point P1, point P2) {// return (p1.x-forwarded X) * (p2.y-forwarded y)-(p2.x-forwarded X) * (p1.y-policy);} int main () {int N; while (CIN> N) {RT. read (); For (INT I = 0; I <n; ++ I) f [I]. read (); F [N] = f [0]; bool OK = true; For (INT I = 0; I <n; ++ I) if (Cross (F [I], F [I + 1], RT) <0) {// outside the edge, OK = false; break;} If (OK) puts ("yes"); else 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.