(周日赛)Friends or Enemies?

题意:判断两点是否在线段的同一方,点不能在线上。

题解:模拟一下

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\n",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 }
时间: 2024-08-05 15:54:56

(周日赛)Friends or Enemies?的相关文章

(周日赛)Sort the Array

题意:一段数字,逆置其中两个使其递增 DescriptionBeing a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of ndistinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agre

(周日赛)Winner

题意:#转 /*玩一个游戏,每轮有一个人得分,或减分,当所有轮完成后,找出分数最高的那个人,如果是多个人,找出那些人中第一个达到最高分或更高的人. 先保存好每个人的分数,记录下究竟有那几个人会得奖,再次遍历所有回合,找出第一个高于等于那个分数的且最终会得奖的人.*/ Sample Input Input 3mike 3andrew 5mike 2 Output andrew Input 3andrew 3andrew 2mike 5 Output andrew 1 #include<stdio.

团 大连网赛 1007 Friends and Enemies

1 //大连网赛 1007 Friends and Enemies 2 // 思路:思路很棒! 3 // 转化成最大二分图 4 // 团:点集的子集是个完全图 5 // 那么朋友圈可以考虑成一个团,原题就转化成用团去覆盖怎样最多.团至少是2个点,所以就是n*n/4 6 7 #include <bits/stdc++.h> 8 using namespace std; 9 #define LL long long 10 typedef pair<int,int> pii; 11 co

赛门铁克23亿美元打造全球最大数字安全平台

作者:茱莉叶 [IT战略家] 赛门铁克打造全球最大数字安全平台   赛门铁克周日同意以23亿美元收购消费者身份防窃取保护服务商LifeLock,打造"全球最大的消费者和家庭数字安全平台",扩展赛门铁克的消费者系列产品. 赛门铁克采用现金和7.5亿美元新债务的形式,以每股24美元,高于LifeLock上周五收盘价16%的价格进行收购.截至上周五,LifeLock股价在2016年上涨了45%,市值达到约19.5亿美元.该交易预计将于2017年第一个季度完成.赛门铁克的董事会也将公司的股票回

2015年ACM长春区域赛比赛感悟

距离长春区域赛结束已经4天了,是时候整理一下这次比赛的点点滴滴了. 也是在比赛前一周才得到通知要我参加长春区域赛,当时也是既兴奋又感到有很大的压力,毕竟我的第一场比赛就是区域赛水平,还是很有挑战性的.在接到通知后,我便开始临阵抱佛脚,课也不怎么听了,上课把时间全都用在了看各种算法上,回到实验室便整理模板.开cf练手.在去比赛前,已经将所看过的算法模板都整理好了. 周五上午9点三刻左右,我们便出发了,需要经历12个小时才能到达我们此次的目的地——长春,途中我还将计算几何稍微看了一下.直到晚上11点

第39届ACM亚洲区域赛牡丹江赛区赛后总结

2014年10月10日,周五,早晨匆匆忙忙的出了寝室,直奔复印社去打了两份模板,然后直接就去上课了.第三节课下课,直接跟老师讲了一声,就去实验室跟学长们汇合了.12点半,踏上了开往牡丹江的列车,我们那节车厢俨然成了参赛队伍的专列了,背后坐的是吉大的,学生还没咋看,主要都看他们教练了,那肚子挺得,那得多腐败啊...旁边的是华南理工的,没想到旁边的那个妹纸,竟然是他们的教练!!!看着就是学生呀,竟然已经留校当教练了,唉,好可惜(你们懂得,嘿嘿~~~) 抵达牡丹江,这是我第二次踏上这块土地,当时想着这

[hdu5136]Yue Fei&#39;s Battle 2014 亚洲区域赛广州赛区J题(dp)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下午有点事情,无法打重现,所以下午只是花了十分钟做了一道J题,抢了个FB,2333333333 Yue Fei's Battle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)T

【转】2014区域赛小结(牡丹江&amp;&amp;鞍山)by kuangbin

Posted on 2014年10月20日 by kuangbin 最后的两场区域赛结束了! ICPC生涯的最后两场区域赛,选择了前两个赛区——牡丹江和鞍山,主要是时间比较靠前,而且我向来对东北赛区有特殊的偏好,我打过的区域赛几乎都是在东北(除了第一年打酱油的时候). 而且特别想回到牡丹江去,在那个曾经打过比赛的地方再打一次比赛,拿回自己想要的. 而且今年岐哥也要打前两场,所以就选择了前两个赛区和岐哥一起打退役赛! 两场比赛采用队名——Final_Battle (最后一战),决心背水一战,认真打

2017区域赛简要小结

仅以此篇献给我即将逝去的2017年 ACM/ICPC系列赛事一站一站地打下去,和NOI系列赛事差不多.理论上说,只要有实力,拿不拿名次都无所谓.但"算法竞赛"的魅力就是如此:能拿WF的门票,能取得名次,这就是实力的证明,也是你追梦成功的证明! 前几天,灿哥约我咖啡,传授了一些"看上去比较显然,但肯定还不能完全理解"的人生道理给我.不过,至少这让我明白了ACM/ICPC赛事的成功之处.目标明确,摒弃杂念,就能持之以恒地向前努力.一个想进final的单纯动机,比很多荣誉