Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int grade[105][105];
- int main(){
- int t,r,c,k,cont=1;
- scanf("%d", &t);
- for(int i=0;i<t;i++){
- scanf("%d%d%d", &r,&c,&k);
- for(int m=1;m<=r;m++){
- for(int n=1;n<=c;n++){
- grade[m][n]=1;
- }
- }
- if(k==(r*c)-1){
- printf("Case #%d: IMPOSSIBLE\n", cont);
- cont++;
- }
- else{
- int ca=0;
- printf("Case #%d: POSSIBLE\n", cont);
- for(int j=1;j<=r;j++){
- for(int l=1;l<=c;l++){
- if(ca==k){
- if(grade[j-1][l]!=0 && grade[j-1][l]!=2){
- grade[j][l]=3;
- printf("N ");
- }
- else if(grade[j][l+1]!=0 && grade[j][l+1]!=2){
- grade[j][l]=3;
- printf("E ");
- }
- else if(grade[j+1][l]!=0 && grade[j+1][l]!=2){
- grade[j][l]=3;
- printf("S ");
- }
- else if(grade[j][l-1]!=0 && grade[j][l-1]!=2){
- grade[j][l]=3;
- printf("W ");
- }
- }
- else{
- ca++;
- if(grade[j-1][l]==0 || grade[j-1][l]==2){
- grade[j][l]=2;
- printf("N ");
- }
- else if(grade[j][l+1]==0 || grade[j][l+1]==2){
- grade[j][l]=2;
- printf("E ");
- }
- else if(grade[j+1][l]==0 || grade[j+1][l]==2){
- grade[j][l]=2;
- printf("S ");
- }
- else if(grade[j][l-1]==0 || grade[j][l-1]==2){
- grade[j][l]=2;
- printf("W ");
- }
- }
- }
- printf("\n");
- }
- cont++;
- }
- for(int a=0;a<105;a++){
- for(int b=0;b<105;b++){
- grade[a][b]=0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement