• hdu 3178 Different Division


    Different Division

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 165    Accepted Submission(s): 75


    Problem Description
    Now we will give you a graph, there are many 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”. Obviously, 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;
     
    Input
    The 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;
     
    Output
    For 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
    1 4 1 1 1 2 3 3 2 1 1 3
     
    Sample Output
    On Left On Right
    该题用差乘来解决,这样就不会出现精度的问题了
     
     
    代码:
     1 #include <cstdio>
     2 #include <iostream>
     3 
     4 using namespace std;
     5 
     6 #define N 1005
     7 #define L 0.0000001
     8 
     9 double a[N];
    10 double b[N];
    11 
    12 int main()
    13 {
    14     int t;
    15     scanf("%d",&t);
    16     while(t--)
    17     {
    18         int n;
    19         scanf("%d",&n);
    20         int i = 0;
    21         for(i = 1; i <= n; i++)
    22             scanf("%lf%lf",&a[i],&b[i]);
    23         int p1,p2;
    24         scanf("%d%d",&p1,&p2);
    25 
    26         double x1 = a[p2] - a[p1];
    27         double y1 = b[p2] - b[p1];
    28 
    29         for(i = 1; i <= n; i++)
    30         {
    31             double x2 = a[i] - a[p1];
    32             double y2 = b[i] - b[p1];
    33 
    34             double sum = x1*y2 - x2*y1;
    35             if(sum < -L)
    36                 printf("Right\n");
    37             else if(sum > L)
    38                 printf("Left\n");
    39             else printf("On\n");
    40         }
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    2017博普杯 东北大学邀请赛(B. Drink too much water)(贪心+树链剖分)
    AGC018D Tree and Hamilton Path(树+树的重心)
    BZOJ2843:极地旅行社
    P++ 1.0.5
    BZOJ1052:[HAOI2007]覆盖问题
    BZOJ3098:Hash Killer II
    BZOJ2784:[JLOI2012]时间流逝
    BZOJ2282:[SDOI2011]消防
    BZOJ1875:[SDOI2009]HH去散步
    Codeforces 504 A (Round #285 div.1 A) Misha and Forest
  • 原文地址:https://www.cnblogs.com/yyroom/p/3002758.html
Copyright © 2020-2023  润新知