poj 3117 Friends or Enemies?(模拟)

题目链接:http://poj.org/problem?id=3119

Friends or Enemies?

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 431   Accepted: 177

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 ≤ MN ≤ 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

Source

South America 2006, Brazil Subregion

题意:

给出一条直线,试判断再给出的点是否在直线的两侧;在两侧就输出“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;
			else
				flag1 = 1;
			if(nod[num2].x*a+b < nod[num2].y)
				flag2 = -1;
			else
				flag2 = 1;
			if(flag1 * flag2 > 0)//同一边
				printf("Mesmo lado da fronteira\n");
			else
				printf("Lados opostos da fronteira\n");
		}

	}
	return 0;
}

poj 3117 Friends or Enemies?(模拟)

时间: 2024-08-04 12:11:40

poj 3117 Friends or Enemies?(模拟)的相关文章

POJ 3087 Shuffle&#39;m Up (模拟+map)

题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去. 现在输入s1和s2的初始状态 以及 预想的最终状态s12.问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1". 解题思路:照着模拟就好了,只是判断是否永远不能达到状态s12需要用map,定义map<

POJ 1027 The Same Game(模拟)

题目链接 题意 : 一个10×15的格子,有三种颜色的球,颜色相同且在同一片内的球叫做cluster(具体解释就是,两个球颜色相同且一个球可以通过上下左右到达另一个球,则这两个球属于同一个cluster,同时cluster含有至少两个球),每次选择cluster中包含同色球最多的进行消除,每次消除完之后,上边的要往下移填满空的地方,一列上的球移动之前与之后相对位置不变,如果有空列,右边的列往左移动,每一列相对位置不变 . 思路 : 模拟......不停的递归..... 1 ////POJ 102

POJ 3282 Ferry Loading IV(模拟,队列)

题意   汽车通过渡船过河  渡船开始在左边   输入按车辆来的顺序输入河两岸的车   渡船每次运输的汽车的总长度不能超过渡船自己本身的长度  先来的车先走   求轮船至少跨河多少次才能将所有的车辆都运完 简单模拟  建两个队列  分别装左边的车  和右边的车   算出两边各至少需要运输多少次就行了 #include<cstdio> #include<cstring> #include<queue> using namespace std; int main() { i

poj 3117 World Cup(简单数学题)

题目链接:http://poj.org/problem?id=3117 World Cup Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8634   Accepted: 4327 Description A World Cup of association football is being held with teams from around the world. The standing is based on

POJ 3119 Friends or Enemies?

先预处理得到各个编号的点的位置再判断 点在二元一次方程的上方还是下方 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <limits.h> #include <malloc.h> #include <ctype.h> #include <math.h> #include <string> #include<iostre

POJ 2424 Flo&#39;s Restaurant 模拟

Flo's Restaurant Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2923   Accepted: 916 Description Sick and tired of pushing paper in the dreary bleary-eyed world of finance, Flo ditched her desk job and built her own restaurant. In the s

poj 1008:Maya Calendar(模拟题,玛雅日历转换)

Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, profes

POJ 3087 Shuffle&#39;m Up(模拟)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several

poj 3087 Shuffle&#39;m Up (模拟过程)

Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several