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:
Stage 2:
Stage 3:
Stage 4:
Stage 5:
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. Thei-th line correspond to the i-th stage.
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.
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
4 4 4 1 3 4 4 1 2 1
Keep talking with your teammates and nobody explodes!
解题思路:
只要读懂题都能做。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int map[10][10]; struct node { int x,y; }num[10000]; int main() { int t; scanf("%d",&t); while(t--) { int i,j,k; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { scanf("%d",&map[i][j]); } } //ok if(map[1][1]==1) { num[1].x=2; num[1].y=map[1][3]; } if(map[1][1]==2) { num[1].x=2; num[1].y=map[1][3]; } if(map[1][1]==3) { num[1].x=3; num[1].y=map[1][4]; } if(map[1][1]==4) { num[1].x=4; num[1].y=map[1][5]; } // if(map[2][1]==1) { for(k=2;k<=5;k++) { if(map[2][k]==4) { num[2].x=k-1; break; } } num[2].y=4; } if(map[2][1]==2||map[2][1]==4) { num[2].x=num[1].x; num[2].y=map[2][num[2].x+1]; } if(map[2][1]==3) { num[2].x=1; num[2].y=map[2][2]; } // if(map[3][1]==1) { for(k=2;k<=5;k++) { if(map[3][k]==num[2].y) { num[3].x=k-1; } } num[3].y=num[2].y; } if(map[3][1]==2) { for(k=2;k<=5;k++) { if(map[3][k]==num[1].y) { num[3].x=k-1; } } num[3].y=num[1].y; } if(map[3][1]==3) { num[3].x=3; num[3].y=map[3][4]; } if(map[3][1]==4) { num[3].y=4; for(k=2;k<=5;k++) { if(map[3][k]==4) { num[3].x=k-1; break; } } } // if(map[4][1]==1) { num[4].x=num[1].x; num[4].y=map[4][num[1].x+1]; } if(map[4][1]==2) { num[4].x=1; num[4].y=map[4][2]; } if(map[4][1]==3||map[4][1]==4) { num[4].x=num[2].x; num[4].y=map[4][num[4].x+1]; } // if(map[5][1]==1) { for(k=2;k<=5;k++) { if(map[5][k]==num[1].y) { num[5].x=k-1; } } num[5].y=num[1].y; } if(map[5][1]==2) { for(k=2;k<=5;k++) { if(map[5][k]==num[2].y) { num[5].x=k-1; } } num[5].y=num[2].y; } if(map[5][1]==3) { for(k=2;k<=5;k++) { if(map[5][k]==num[4].y) { num[5].x=k-1; } } num[5].y=num[4].y; } if(map[5][1]==4) { for(k=2;k<=5;k++) { if(map[5][k]==num[3].y) { num[5].x=k-1; } } num[5].y=num[3].y; } // for(i=1;i<=5;i++) { printf("%d %d\n",num[i].x,num[i].y); } } return 0; }