poj 3119 Friends or Enemies?(模拟)
来源:互联网 发布:tensorflow网络微调 编辑:程序博客网 时间:2024/06/01 07:26
题目链接:http://poj.org/problem?id=3119
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
21 21026 2525 1124 923 2825 925 125 09 123 1226 171 2120 11 22 33 44 55 66 77 88 99 1010 1111 12
Sample Output
Caso 1Mesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraLados opostos da fronteiraLados opostos da fronteiraLados opostos da fronteiraLados opostos da fronteiraLados opostos da fronteiraCaso 2Mesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraLados opostos da fronteiraMesmo lado da fronteiraMesmo lado da fronteiraLados opostos da fronteira
Source
题意:
给出一条直线,试判断再给出的点是否在直线的两侧;在两侧就输出“Lados opostos da fronteira”;在同侧就输出“Mesmo lado da fronteira”;
当然所给的点不是坐标,而是一个数字, 这个数字按照一定的顺序有一个固定坐标,我们需要先把这两个数字的坐标按照给定的顺序找出来在判断在同侧还是异侧;
代码如下:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;int xx[4] = {-1,0,1,0};//顺序左、上、右、下int yy[4] = {0,1,0,-1};struct tt{int x, y;}nod[70017];int main(){int t;int a, b;int n;int cas = 0;scanf("%d",&t);while(t--){printf("Caso %d\n",++cas);scanf("%d%d",&a,&b);int x = 0, y = 0;//原点为起始点int num = 0;int flag = 0;//标记if(b != 0)//原点不在直线上{nod[num].x = x;nod[num].y = y;num++;}flag++;int ff = 0;x += xx[ff];y += yy[ff];ff = (ff+1)%4;//四个方向一循环int cont = 0;int limit = 1;while(num <= 65535)//先跑出每个点所在的位置{if(a*x+b != y)//当前点不在直线上{nod[num].x = x;nod[num].y = y;num++;}cont++;x += xx[ff];y += yy[ff];if(cont == limit){ff = (ff+1)%4;cont = 0;flag++;}if(flag == 2)//因为所走的矩形是一个长方形{//需要连续走两次步数相同的边flag = 0;limit++;}}scanf("%d",&n);int num1, num2;int flag1,flag2;for(int i = 0; i < n; i++){scanf("%d%d",&num1,&num2);if(nod[num1].x*a+b < nod[num1].y)flag1 = -1;elseflag1 = 1;if(nod[num2].x*a+b < nod[num2].y)flag2 = -1;elseflag2 = 1;if(flag1 * flag2 > 0)//同一边printf("Mesmo lado da fronteira\n");elseprintf("Lados opostos da fronteira\n");}}return 0;}
- poj 3119 Friends or Enemies?(模拟)
- POJ 3119 Friends or Enemies?
- POJ 3119 Friends or Enemies? 模拟 计算题 需要预处理
- POJ 3119 Friends or Enemies? (模拟一遍,函数的魅力)
- POJ 3119 Friends or Enemies? 笔记
- POJ 2269 Friends(模拟)
- hdu5874 Friends and Enemies(脑洞题)
- HDU 5874 Friends and Enemies(构造)
- 【HDU5874】Friends and Enemies(思维)
- hdu 5874 Friends and Enemies(思维)
- HDU5874 Friends and Enemies
- HDU5874 Friends and Enemies
- HDU5874-Friends and Enemies
- Friends and Enemies HDU
- HDU 5874 Friends and Enemies
- hdu 5874 Friends and Enemies
- HDU 5874 Friends and Enemies
- HDU-5874-Friends and Enemies
- c#图片上写字
- Path Sum II(LeetCode)
- 中国国家气象局天气预报接口
- oracle 11g RAC crfclust.bdb过大的处理
- Android界面特效全汇总
- poj 3119 Friends or Enemies?(模拟)
- 系统杂类------让bat,cmd文件后台运行
- hdu2012- A计划
- 黑马程序员——java中的基本数据类型
- 简简单单的代码让你轻松学会 动态代理
- 数据结构学习笔记:二叉树
- C#的假死问题
- 学生信息管理系统——整体构思
- nyist oj 58 最少步数(dfs搜索)