ACM刷题之ZOJ————Defuse the Bomb
2016-04-27 15:27
323 查看
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.
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.
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.
i-th stage.
—————————————————————————————————————————————————————————————————————————————
这个是The 13th Zhejiang Provincial Collegiate Programming Contest 的题目(参加了现场赛)。
其实就是一道模拟题。但是比赛的时候没有先选择做这题,导致了时间不够,有点遗憾。
用结构体的话会更加方便。
下面是ac代码
细心点的话不难的
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.
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 thei-th stage.
Sample Input
1 4 2 1 3 4 2 2 4 3 1 4 3 1 4 2 4 3 4 2 1 2 3 1 2 4
Sample Output
4 4 4 1 3 4 4 1 2 1
Hint
Keep talking with your teammates and nobody explodes!—————————————————————————————————————————————————————————————————————————————
这个是The 13th Zhejiang Provincial Collegiate Programming Contest 的题目(参加了现场赛)。
其实就是一道模拟题。但是比赛的时候没有先选择做这题,导致了时间不够,有点遗憾。
用结构体的话会更加方便。
下面是ac代码
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<algorithm> using namespace std; typedef struct stage { int lable[5]; int position[5]; int act; int labmem; int posmem; }stage; int main() { int n,i,j,fla,k; stage a[6]; scanf("%d",&n); while(n--) { for(i=1;i<=5;i++) { scanf("%d",&a[i].act); k=0; for(j=1;j<=4;j++) { scanf("%d",&a[i].lable[j]); k++; a[i].position[j]=k; } } ///////////////////input over //////stage one if(a[1].act==1||a[1].act==2) { printf("2 %d\n",a[1].lable[2]); a[1].labmem=a[1].lable[2]; a[1].posmem=2; } else if(a[1].act==3) { printf("3 %d\n",a[1].lable[3]); a[1].labmem=a[1].lable[3]; a[1].posmem=3; } else if(a[1].act==4) { printf("4 %d\n",a[1].lable[4]); a[1].labmem=a[1].lable[4]; a[1].posmem=4; } //////one over /////stage two if(a[2].act==1) { for(i=1;i<=4;i++) { if(a[2].lable[i]==4) { printf("%d %d\n",a[2].position[i],a[2].lable[i]); a[2].labmem=a[2].lable[i]; a[2].posmem=a[2].position[i]; break; } } } else if(a[2].act==2||a[2].act==4) { printf("%d %d\n",a[2].position[a[1].posmem],a[2].lable[a[1].posmem]); //If the display is 2, press the button in the same position as you pressed in stage 1. a[2].labmem=a[2].lable[a[1].posmem]; a[2].posmem=a[2].position[a[1].posmem]; } else if(a[2].act==3) { printf("%d %d\n",a[2].position[1],a[2].lable[1]); a[2].labmem=a[2].lable[1]; a[2].posmem=a[2].position[1]; } ////////two over ///////stage three if(a[3].act==1) { for(i=1;i<=4;i++) { if(a[3].lable[i]==a[2].labmem) { printf("%d %d\n",a[3].position[i],a[3].lable[i]); a[3].labmem=a[3].lable[i]; a[3].posmem=a[3].position[i]; break; } } //If the display is 1, press the button with the same label you pressed in stage 2 } else if(a[3].act==2) { for(i=1;i<=4;i++) { if(a[3].lable[i]==a[1].labmem) { printf("%d %d\n",a[3].position[i],a[3].lable[i]); a[3].labmem=a[3].lable[i]; a[3].posmem=a[3].position[i]; break; } } } else if(a[3].act==3) { printf("3 %d\n",a[3].lable[3]); a[3].labmem=a[3].lable[3]; a[3].posmem=3; } else if(a[3].act==4) { for(i=1;i<=4;i++) { if(a[3].lable[i]==4) { printf("%d 4\n",a[3].position[i]); a[3].labmem=4; a[3].posmem=a[3].position[i]; break; } } } ///////three over //////stage four if(a[4].act==1) { printf("%d %d\n",a[4].position[a[1].posmem],a[4].lable[a[1].posmem]); a[4].labmem=a[4].lable[a[1].posmem]; a[4].posmem=a[4].position[a[1].posmem]; } else if(a[4].act==2) { printf("1 %d\n",a[4].lable[1]); a[4].labmem=a[4].lable[1]; a[4].posmem=1; } else if(a[4].act==3||a[4].act==4) { printf("%d %d\n",a[4].position[a[2].posmem],a[4].lable[a[2].posmem]); a[4].labmem=a[4].lable[a[2].posmem]; a[4].posmem=a[4].position[a[2].posmem]; } /////four over /////stage five if(a[5].act==1) { for(i=1;i<=4;i++) { if(a[5].lable[i]==a[1].labmem) { printf("%d %d\n",a[5].position[i],a[5].lable[i]); break; } } } else if(a[5].act==2) { for(i=1;i<=4;i++) { if(a[5].lable[i]==a[2].labmem) { printf("%d %d\n",a[5].position[i],a[5].lable[i]); break; } } } else if(a[5].act==3) { for(i=1;i<=4;i++) { if(a[5].lable[i]==a[4].labmem) { printf("%d %d\n",a[5].position[i],a[5].lable[i]); break; } } } else if(a[5].act==4) { for(i=1;i<=4;i++) { if(a[5].lable[i]==a[3].labmem) { printf("%d %d\n",a[5].position[i],a[5].lable[i]); break; } } } //////over } }
细心点的话不难的
相关文章推荐
- 利用Multipeer Connectivity框架进行WiFi传输
- WS架构:webapp数据交互与实时数据
- 2016-4-27知识整理
- 使用sed替换替换指定行的日期部分
- PHP 时间戳转化为日期格式
- UML类图
- ubuntu 解压命令集合
- PHPStorm8 常用快捷键
- JAVA设计模式之单例模式
- Oracle kill inactive 线程
- Tensorflow学习笔记(7)——CNN识别mnist编程实现
- 文档去重算法:SimHash和MinHash
- 搜索后再分页
- Exercise(8):单色汉诺塔
- ViewPager 详解(五)-----使用Fragment实现ViewPager滑动
- Java内存泄露原因详解
- Git学习4:常用命令小结
- CreateThread函数&&CString::GetBuffer函数
- docker安装(centos 7.2)
- 35 个 Java 代码性能优化总结