HDU 3718 different division

Source: Internet
Author: User
Different divisiontime limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others) Total submission (s): 234 accepted submission (s): 90

Problem descriptionnow we will give you a graph, there are getting points in the graph. we will choose two different points arbitrarily, and connect them as a line. please tell us that whether these points (include the two points referred above) is on the left side of the line, or lying on the line. or on the right side of the line. for example,

There are four points in the graph: A, B, C, D. we connect C and D. now C and D form a new line "cd ". obviusly, C and D are lying on the line "CD ". A is on the right side of Cd, and B is on the left side of CD. what's more, A is on the left side of line DC, and B is on the right side of line DC. so line "CD" and "DC" are different in this problem;
 
Inputthe first line of input is a single integer T, indicating the number of test cases. then exactly t test cases followed. in each case, the first line contains one INTEGER: N, the number of points. then n lines followed, each line contains two real numbers x, y, indicating the coordinates of points. then one line follows, contains two integers P1 and P2 indicate the p1th point and the p2th point in this case.
1 <= T <= 100
2 <= n <= 1000
1 <= p1, p2 <= N, P1! = P2
-1000 <X, Y <1000;
 
Outputfor each case, print n lines. according to the order of input, for each point print "left" if this point is on the left side of Line P1P2, or "on" if this point is lying on line P1P2, or "right" if this is on the right side of Line P1P2.
Sample Input
141 1 1 2 3 3 2 1 1 3
 
Sample output
OnLeftOnRight
Idea: Cross Product
<span style="font-size:18px;">#include <cstdio>#include <iostream>using namespace std;#define N 1005double a[N],b[N];int main(){int t;double x1,x2,y1,y2,sum;scanf("%d",&t);while(t--){int n,i;scanf("%d",&n);for(i = 1; i <= n; i++)scanf("%lf%lf",&a[i],&b[i]);int p1,p2;        scanf("%d%d",&p1,&p2); x1 = a[p2] - a[p1]; y1 = b[p2] - b[p1];for(i=1; i<=n; i++){ x2 = a[i] - a[p1]; y2 = b[i] - b[p1];    sum = x1*y2 - x2*y1;if(sum < 0)printf("Right\n");else if(sum > 0)printf("Left\n");else printf("On\n");        }}return 0;}</span>


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.