zoj-3938

刺骨的言语ヽ痛彻心扉 2022-05-26 09:21 260阅读 0赞

Defuse the Bomb


Time Limit: 2 Seconds Memory Limit: 65536 KB


The bomb is about to explode! Please defuse it as soon as possible!

There is a display showing a number from 1 to 4 on the bomb. Besides this, there are 4 buttons under the display. Each button is labeled by a number from 1 to 4. The numbers on the buttons are always distinct.

showImage.do_name_zjcpc_bomb.png

There are 5 defusing stages in total. Pressing the correct button can progress the bomb to the next defusing stage. The number on the display and the number on each button may be different in different stages. The bomb will be defused only when all 5 defusing stages get passed. Pressing the incorrect button will cause the bomb to explode immediately. Be careful!

Here is the detailed bomb defusing manual. Button positions are ordered from left to right.

Stage 1:

  • If the display is 1, press the button in the second position.
  • If the display is 2, press the button in the second position.
  • If the display is 3, press the button in the third position.
  • If the display is 4, press the button in the fourth position.

Stage 2:

  • If the display is 1, press the button labeled “4”.
  • If the display is 2, press the button in the same position as you pressed in stage 1.
  • If the display is 3, press the button in the first position.
  • If the display is 4, press the button in the same position as you pressed in stage 1.

Stage 3:

  • If the display is 1, press the button with the same label you pressed in stage 2.
  • If the display is 2, press the button with the same label you pressed in stage 1.
  • If the display is 3, press the button in the third position.
  • If the display is 4, press the button labeled “4”.

Stage 4:

  • If the display is 1, press the button in the same position as you pressed in stage 1.
  • If the display is 2, press the button in the first position.
  • If the display is 3, press the button in the same position as you pressed in stage 2.
  • If the display is 4, press the button in the same position as you pressed in stage 2.

Stage 5:

  • If the display is 1, press the button with the same label you pressed in stage 1.
  • If the display is 2, press the button with the same label you pressed in stage 2.
  • If the display is 3, press the button with the same label you pressed in stage 4.
  • If the display is 4, press the button with the same label you pressed in stage 3.

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:

There are 5 lines. Each line contains 5 integers D, B1, B2, B3, B4 indicating the number on the display and the numbers on the buttons respectively. The i-th line correspond to the i-th stage.

Output

For each test case, output 5 lines. The i-th line contains two integers indicating the position and the label of the correct button for the i-th stage.

Sample Input

  1. 1
  2. 4 2 1 3 4
  3. 2 2 4 3 1
  4. 4 3 1 4 2
  5. 4 3 4 2 1
  6. 2 3 1 2 4

Sample Output

  1. 4 4
  2. 4 1
  3. 3 4
  4. 4 1
  5. 2 1

Hint

Keep talking with your teammates and nobody explodes!


Author: JIANG, Kai

Source: The 13th Zhejiang Provincial Collegiate Programming Contest

题目大意:

按要求要经过 5 个阶段,每个阶段会显示 1—4 中的一个数,且有 1—4 号按钮,

根据显示数的不同来决定按钮的不同,依次显示该按钮的位置和编号。

思路:模拟,

代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5. int a[10][10];
  6. struct node
  7. {
  8. int x,y;
  9. }num[10000];
  10. int main()
  11. {
  12. int t;
  13. scanf("%d",&t);
  14. while(t--)
  15. {
  16. int i,j,k;
  17. for(i=1;i<=5;i++)
  18. {
  19. for(j=1;j<=5;j++)
  20. {
  21. scanf("%d",&a[i][j]);
  22. }
  23. }
  24. if(a[1][1]==1)//stage1
  25. {
  26. num[1].x=2;
  27. num[1].y=a[1][3];
  28. }
  29. if(a[1][1]==2)
  30. {
  31. num[1].x=2;
  32. num[1].y=a[1][3];
  33. }
  34. if(a[1][1]==3)
  35. {
  36. num[1].x=3;
  37. num[1].y=a[1][4];
  38. }
  39. if(a[1][1]==4)
  40. {
  41. num[1].x=4;
  42. num[1].y=a[1][5];
  43. }
  44. if(a[2][1]==1)//stage2
  45. {
  46. for(k=2;k<=5;k++)
  47. {
  48. if(a[2][k]==4)
  49. {
  50. num[2].x=k-1;
  51. break;
  52. }
  53. }
  54. num[2].y=4;
  55. }
  56. if(a[2][1]==2||a[2][1]==4)
  57. {
  58. num[2].x=num[1].x;
  59. num[2].y=a[2][num[2].x+1];
  60. }
  61. if(a[2][1]==3)
  62. {
  63. num[2].x=1;
  64. num[2].y=a[2][2];
  65. }
  66. //stage3
  67. if(a[3][1]==1)
  68. {
  69. for(k=2;k<=5;k++)
  70. {
  71. if(a[3][k]==num[2].y)
  72. {
  73. num[3].x=k-1;
  74. }
  75. }
  76. num[3].y=num[2].y;
  77. }
  78. if(a[3][1]==2)
  79. {
  80. for(k=2;k<=5;k++)
  81. {
  82. if(a[3][k]==num[1].y)
  83. {
  84. num[3].x=k-1;
  85. }
  86. }
  87. num[3].y=num[1].y;
  88. }
  89. if(a[3][1]==3)
  90. {
  91. num[3].x=3;
  92. num[3].y=a[3][4];
  93. }
  94. if(a[3][1]==4)
  95. {
  96. num[3].y=4;
  97. for(k=2;k<=5;k++)
  98. {
  99. if(a[3][k]==4)
  100. {
  101. num[3].x=k-1;
  102. break;
  103. }
  104. }
  105. }
  106. //stage4
  107. if(a[4][1]==1)
  108. {
  109. num[4].x=num[1].x;
  110. num[4].y=a[4][num[1].x+1];
  111. }
  112. if(a[4][1]==2)
  113. {
  114. num[4].x=1;
  115. num[4].y=a[4][2];
  116. }
  117. if(a[4][1]==3||a[4][1]==4)
  118. {
  119. num[4].x=num[2].x;
  120. num[4].y=a[4][num[4].x+1];
  121. }
  122. //stage4
  123. if(a[5][1]==1)
  124. {
  125. for(k=2;k<=5;k++)
  126. {
  127. if(a[5][k]==num[1].y)
  128. {
  129. num[5].x=k-1;
  130. }
  131. }
  132. num[5].y=num[1].y;
  133. }
  134. //stage5
  135. if(a[5][1]==2)
  136. {
  137. for(k=2;k<=5;k++)
  138. {
  139. if(a[5][k]==num[2].y)
  140. {
  141. num[5].x=k-1;
  142. }
  143. }
  144. num[5].y=num[2].y;
  145. }
  146. if(a[5][1]==3)
  147. {
  148. for(k=2;k<=5;k++)
  149. {
  150. if(a[5][k]==num[4].y)
  151. {
  152. num[5].x=k-1;
  153. }
  154. }
  155. num[5].y=num[4].y;
  156. }
  157. if(a[5][1]==4)
  158. {
  159. for(k=2;k<=5;k++)
  160. {
  161. if(a[5][k]==num[3].y)
  162. {
  163. num[5].x=k-1;
  164. }
  165. }
  166. num[5].y=num[3].y;
  167. }
  168. for(i=1;i<=5;i++)
  169. {
  170. printf("%d %d\n",num[i].x,num[i].y);
  171. }
  172. }
  173. return 0;
  174. }

发表评论

表情:
评论列表 (有 0 条评论,260人围观)

还没有评论,来说两句吧...

相关阅读

    相关 zoj1002

    [题目传送门][Link 1] 题目大意: 在一个最大为4\4的方格内建blockhouse( 碉堡) 但是有条件 1. 两个及以上blockhouse不能

    相关 Zoj 2947——Abbreviation

    呵呵哒,一开始觉的很难,是因为题长,以后不能被长题再坑了!后来耐下性子读,才发现就是让比对缩写是否相同,我用字符数组写的,当时还开了二维数组,现在想来,实在是笨,不好意思再贴!

    相关 ZOJ 3941

    题意:有n(10)段时间,会举行party,每个party有开始时间,结束时间,不同party举行时间可能重复。(时间范围为1~1e9) 我们一共最多可以参加m(1e9)