2 shunfurh shunfurh 于 2017.01.05 23:37 提问

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个回答

caozhy
caozhy   Ds   Rxr 2017.01.05 23:50
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
POJ 3119 Friends or Enemies?
先预处理得到各个编号的点的位置再判断 点在二元一次方程的上方还是下方#include #include #include #include #include #include #include #include #include #include using namespace std; #define MAXN 11111 #include #include struct
HDU5874 Friends and Enemies
题目: http://acm.split.hdu.edu.cn/showproblem.php?pid=5874 题意: M个人互相之间不是朋友就是敌人,朋友有至少一个颜色一样的石头,敌人不能有任何颜色一样的石头。求N个石头是否满足情况。 思路: 就是M个节点的图是朋友就建边那么每条边代表有一样的石头,边越多石头颜色就越多,但是如果存在子图是完全图,这个子图中的所有边可以是一个颜色的
Friends and Enemies HDU - 5874
On an isolated island, lived some dwarves. A king (not a dwarf) ruled the island and the seas nearby, there are abundant cobblestones of varying colors on the island. Every two dwarves on the island ar
【HDU5874】Friends and Enemies(思维)
题目大意: 有M个人,每个人不是朋友就是敌人,如果两个人是朋友则项链至少有一种颜色相同,是敌人则没有相同颜色,问N种颜色是否满足条件。我们假设x个人互相敌对,然后有y个人与这x个人都是朋友,而这y个人互相敌对。 则有 x+y=m x*y<=n 当x 和 y相等时,x*y<=m^2/4; 判断n和m^2/4的大小。 题解摘自:http://www.cnblogs.
hdu 5874 Friends and Enemies
题目题意:某座岛上 有m个人,有n种颜色的珠子。现在每个人必须要带上一个项链。人与人之间要么是朋友要么是敌人。 如果是朋友,那么他们的项链必须有至少一个相同颜色的珠子,否则他们的项链不能有任何一个相同颜色的珠子。解:现在需要知道最多需要种多少颜色的珠子才能解决问题。 假设一开始所有人的项链上都没有珠子,那么当前答案是0,所有人互为敌人。 由于朋友关系,会使答案增加,现在开始考虑某一个人的朋友关
HDU 5874 Friends and Enemies
Problem Description On an isolated island, lived some dwarves. A king (not a dwarf) ruled the island and the seas nearby, there are abundant cobblestones of varying colors on the island. Every two
NFV&SDN: Friends or Enemies?
最近在看移动边缘计算系统架构相关的内容,其中多次提到了NFV和SDN是Mobile Edge Computing网络实现的基础,之前对两个名词不了解,今天搜集了一些这方面的资料,整理一下,分享给大家。原作者:Justyna Bak Sr. Product Marketing Manager Riverbed Technolog1. 目标SDN的目的是将控制平面和数据平面解耦,使控制层平面变为可编
HDU 5874 Friends and Enemies(构造)
Description 有m个人n种珠子,现在要用这些种珠子给m个人每人串一条项链(长度可以为0),两个人之间要么是朋友关系要么是敌人关系,要求两个人是朋友时他们的项链必须至少有一个颜色相同的珠子,两个人是敌人时他们的项链必须没有颜色相同的珠子,判断这n种珠子是否能满足条件 Input 多组用例,每组用例输入两个整数m和n分别表示人数和珠子种类数,以文件尾结束输入(m,n<2^31) Out
POJ 3119 Friends or Enemies? 笔记
如插图,直线 y = ax + b ,a,b 是整数。不算直线上的点,原点为 0 ,从原点开始顺时针记数,每个位置赋予一个整数。给出 K 个查询,查询两个整数位置是在同侧还是在异侧。
hdu 5874 Friends and Enemies(思维)
On an isolated island, lived some dwarves. A king (not a dwarf) ruled the island and the seas nearby, there are abundant cobblestones of varying colors on the island. Every two dwarves on the island ar