首页 > 其他分享 >UVa 11507 Bender B. Rodríguez Problem (模拟&异或)

UVa 11507 Bender B. Rodríguez Problem (模拟&异或)

时间:2023-04-12 11:34:39浏览次数:47  
标签:wire point 11507 each guez 异或 Bender sgn axis


11507 - Bender B. Rodríguez Problem

Time limit: 4.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2502

Bender is a robot built by Mom's Friendly Robot Company at its plant in Tijuana, Mexico in 2996 . He is aBending-Unit 22, serial number 2716057 and chassis number 1729

Bender needs to bend a wire of length L (L 2 an integer). The wire is represented in the Bender's brain (aMOS Technology 6502 microprocessor) as a line stucked in the origin of a tridimensional cartesian coordinate system, and extended along the x positive axis (+x), so that the fixed extreme of the wire is in the coordinate (0,0,0) and the free extreme of the wire is in the coordinate (L,0,0).




Bender bends the wire at specific points, starting at the point (L-1,0,0) and ending at the point (1,0,0). For each i from L-1 to 1, Bender can take one of the following decisions:

  • Not to bend the wire at point (i,0,0).
  • To bend the wire at point (i,0,0) an angle of  to be parallel to the axis +y, -y, +z or -z.


For example, if L=3 and Bender bends the wire at (2,0,0) on the +y axis direction, and at (1,0,0) on the -yaxis direction, the result would be:







Given a sequence of bends, you must determine what direction is pointed by the last segment of the wire (+xin the example). You can suppose that the wire can intercept itself, after all it is the future!


Input

The first line of each test case gives an integer L (2 L 100000) indicating the length of the wire.



The second line of each test case contains the L-1 decisions taken by Bender at each point, separated by spaces. The j-th decision in the list (for each 1 j L-1) corresponds to the decision taken at the point(L-j,0,0), and must be one of the following:


  • No if the wire isn't bended at point (L-j,0,0).
  • +y if the wire is bended at point (L-j,0,0) on the +y
  • -y if the wire is bended at point (L-j,0,0) on the -y
  • +z if the wire is bended at point (L-j,0,0) on the +z
  • -z if the wire is bended at point (L-j,0,0) on the -z

The end of the input is indicated when L=0.


Output

For each case in the input, print one line with the direction pointed by the last segment of the wire, +x, -x, +y, -y, +z or -z


Sample Input


3+z -z3
+z +y
2
+z
4
+z +y +z
5
No +z No No
0



Sample Output


+x+z+z
-x
+z



有以下公式:

1. +y -y = +x

2. +y +y = -x

3. +y (+/-)z = +y

4. 由2、3得 +y ±z ±(+/-)z ... (+/-)z +y = -x

5. -x (+/-)y = (-/+)y


完整代码:


/*0.019s*/

#include<cstdio>

int main()
{
	int n;
	bool sgn;
	char axis, ch1, ch2;
	while (scanf("%d\n", &n), n)
	{
		sgn = true, axis = 'x';
		while (--n)
		{
			ch1 = getchar(), ch2 = getchar(), getchar();
			if (ch1 == 'N') continue;
			if (axis == 'x')
				sgn = !(sgn ^ (ch1 == '+')), axis = ch2;
			else if (ch2 == axis)
				sgn = sgn ^ (ch1 == '+'), axis = 'x';
		}
		putchar(sgn ? '+' : '-'), putchar(axis), putchar(10);
	}
	return 0;
}






标签:wire,point,11507,each,guez,异或,Bender,sgn,axis
From: https://blog.51cto.com/u_5535544/6185340

相关文章

  • 与& 或| 异或^ 的三个常见用途
    与&或|异或^的三个常见用途1.与&作为掩码(bitmask)屏蔽比特串的一部片/提取比特串的一部分a=0b11010101#Binaryb=0b00000111#Bitmaskc=a&b#c=0b00000101#b作为掩码和a进行与操作后,保留了a的后三位,其余位全设为0被屏蔽了2.或|设1(set)a=0b11010101#......
  • 4月7日leetcode随笔,异或的灵活运用
    给你一个非空整数数组nums,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。你必须设计并实现线性时间复杂度的算法来解决此问题,且该算法只使用常量额外空间。来源:力扣(LeetCode)链接:https://leetcode.cn/problems/single-number著作权归领扣......
  • 一篇关于异或操作的题解 (来源:杭电oj: find your present (2))
    害惭愧惭愧老长时间没写代码了——————————转回正题,对于杭电这个题先说我超时的错误想法—————————————————————————————————————————————————————————————— 一开始我的想法是开一个大小为100000......
  • 异或运算^无符号右移>>>&与运算
    1. <<(向左位移)针对二进制,转换成二进制后向左移动2位,后面用0补齐10的二进制101000000000000000000000000000001010---32位00000000000000000000000000101......
  • 寄存器修改指定位不影响其他位, 位与&、位或|、位异或^
    一、位与&(位清零用)位与特点:任何数(0或1),和1,位与无变化;和0,位与变成0真值表: 1&1=1   0&0=0  1&0=0   0&1=0代码:#include<stdio.h>intmain(void){u......
  • Warmup:Upanishad (异或的减法思维,排序预处理,后按顺序处理, 树状数组,贪心第把数往
       后记: ......
  • s2oj2046 GDKOI2023 Day1T3 异或图
    s2oj2046GDKOI2023Day1T3异或图好题,与Ex-DistinctMultiples类似,题解。首先考虑没有边的情况,那么我们需要满足条件\(1,3\)。考虑从高位开始计算,设当前考虑到第......
  • 算法题——最大异或和
    题目代码#include<iostream>#include<stdio.h>#include<cstring>#include<algorithm>usingnamespacestd;constintN=3100000+10;intn,m;inttrie[N][2],cn......
  • 变量交换方法(使用按位异或操作符)
    按位异或操作符:^作用:一个整形在计算机中按二进制存储,按位异或即按二进制位将两个数对比,相同为0,相反为1;举例如下:1#include<stdio.h>23intmain()4{5......
  • 1310. 子数组异或查询 (Medium)
    问题描述1310.子数组异或查询(Medium)有一个正整数数组arr,现给你一个对应的查询数组queries,其中queries[i]=[Lᵢ,Rᵢ]。对于每个查询i,请你计算从Lᵢ到Rᵢ......