题意:判断两点是否在线段的同一方,点不能在线上。
题解:模拟一下
Description
A determined army on a certain border decided to enumerate the coordinates in its patrol in a way to make it difficult for the enemy to know what positions they are referring to in the case that the radio signal used for communication is intercepted. The enumeration process chosen was the following: first it is decided where the axes x and y are; then, a linear equation that describes the position of the border relative to the the axes (yes, it is a straight line) is defined; finally, all points on the Cartesian plane that is not part of the border are enumerated, the number 0 being attributed to the coordinate (0, 0) and starting from there numbers being attributed to integral coordinates following a clockwise spiral, always skipping points that fall on the border (see Figure 1). If the point (0, 0) falls on the border, the number 0 is attributed to the first point that is not part of the border following the specified order.
Figure 1: Enumeration of points of integral coordinates
In fact the enemy does not have to know either what position the army is referring to or the system used to enumerate the points. Such a project, complicated the life of the army, once that it is difficult to determine whether two points are on the same side of the border or on opposite sides. That is where they need your help.
Input
The input contains several test cases. The first line of the input contains an integer N (1 ≤ N ≤ 100) which represents the quantity of test cases. N test cases follow. The first line of each test case contains two integers a and b (−5 ≤ a ≤ 5 and −10 ≤ b ≤ 10) which describe the equation of the border: y = ax + b. The second line of each test case contains an integer K, indicating the number of queries that follow it (1 ≤ K ≤ 1000). Each one of the following K lines describes a query, composed by two integers M and N representing the enumerated coordinates of two points (0 ≤ M, N ≤ 65535).
Output
For each test case in the input your program should produce K + 1 lines. The first line should contain the identification of the test case in the form Caso X, where X should be substituted by the case number (starting from 1). The K following lines should contain the results of the K queries made in the corresponding case in the input, in the form:
Mesmo lado da fronteira (The same side of the border)
or
Lados opostos da fronteira (Opposite sides of the border)
Sample Input
2
1 2
10
26 25
25 11
24 9
23 28
25 9
25 1
25 0
9 1
23 12
26 17
1 2
12
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
Sample Output
Caso 1
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Lados opostos da fronteira
Lados opostos da fronteira
Lados opostos da fronteira
Lados opostos da fronteira
Lados opostos da fronteira
Caso 2
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Lados opostos da fronteira
Mesmo lado da fronteira
Mesmo lado da fronteira
Lados opostos da fronteira
1 #include<stdio.h> 2 3 struct point 4 { 5 int x,y; 6 }stu[10000]; 7 8 int main() 9 { 10 int t,n,m,a,b,k,i,j,ti=1; 11 int biaoji1,biaoji2; 12 scanf("%d",&t); 13 while(t--) 14 { 15 printf("Caso %d ",ti++); 16 scanf("%d %d",&a,&b); 17 scanf("%d",&k); 18 int x=0,y=0; 19 int diyici=1; 20 int num=-1; 21 int flag=0; 22 int bu=1;//两次一步 23 int tem=1; 24 while(num<10000) 25 { 26 if(a*x+b!=y)//不在线上 27 { 28 num++; 29 stu[num].x=x; 30 stu[num].y=y; 31 } 32 if(flag==0) 33 { 34 x--; 35 } 36 else if(flag==1) 37 { 38 y++; 39 } 40 else if(flag==2) 41 { 42 x++; 43 } 44 else if(flag==3) 45 { 46 y--; 47 } 48 bu--; 49 if(bu==0&&diyici==1) 50 { 51 bu=tem; 52 flag++; 53 flag%=4;; 54 diyici=2; 55 } 56 else if(bu==0&&diyici==2) 57 { 58 bu=++tem; 59 flag++; 60 flag%=4;; 61 diyici=1; 62 } 63 64 } 65 while(k--) 66 { 67 scanf("%d %d",&m,&n); 68 biaoji1=a*stu[m].x+b-stu[m].y; 69 biaoji2=a*stu[n].x+b-stu[n].y; 70 if(biaoji1*biaoji2<0) 71 puts("Lados opostos da fronteira"); 72 else 73 puts("Mesmo lado da fronteira"); 74 } 75 } 76 return 0; 77 }