#include<stdio.h>#include<string.h>constintTRUE=1;constintFALSE=0;intstone_X[102];intstone_Y[102];intstone_vistied[102];intnumber_of_stones;intjump(intjump_power,intx,inty,intfinish_X,intfinish_Y);intmain(){intT=0;inti=0;intj=0;intjump_power=0;intstart_X=0;intstart_Y=0;intfinish_X=0;intfinish_Y=0;intresult=0;scanf("%d",&T);for(j=0;j<T;j++){scanf("%d",&jump_power);scanf("%d",&start_X);scanf("%d",&start_Y);scanf("%d",&finish_X);scanf("%d",&finish_Y);scanf("%d",&number_of_stones);memset(stone_X,0x00,sizeof(stone_X));memset(stone_Y,0x00,sizeof(stone_Y));memset(stone_vistied,0x00,sizeof(stone_vistied));//set NOT visited.for(i=0;i<number_of_stones;i++){scanf("%d",&stone_X[i]);scanf("%d",&stone_Y[i]);}result=jump(jump_power,start_X,start_Y,finish_X,finish_Y);if(result==0){printf("NO\n");}else{printf("YES\n");}}}intjump(intjump_power,intx,inty,intfinish_X,intfinish_Y){inti=0;intj=0;intcheck_if_finshed=0;for(i=1;i<=jump_power;i++){for(j=0;j<number_of_stones;j++){if(((x-i)==finish_X)&&(y==finish_Y))returnTRUE;if(((x-i)==stone_X[j])&&(y==stone_Y[j])){if(stone_vistied[j]==FALSE){stone_vistied[j]=TRUE;check_if_finshed+=jump(jump_power,stone_X[j],stone_Y[j],finish_X,finish_Y);}}if(((x+i)==finish_X)&&(y==finish_Y))returnTRUE;if(((x+i)==stone_X[j])&&(y==stone_Y[j])){if(stone_vistied[j]==FALSE){stone_vistied[j]=TRUE;check_if_finshed+=jump(jump_power,stone_X[j],stone_Y[j],finish_X,finish_Y);}}if((x==finish_X)&&((y+i)==finish_Y))returnTRUE;if(((x)==stone_X[j])&&((y+i)==stone_Y[j])){if(stone_vistied[j]==FALSE){stone_vistied[j]=TRUE;check_if_finshed+=jump(jump_power,stone_X[j],stone_Y[j],finish_X,finish_Y);}}if((x==finish_X)&&((y-i)==finish_Y))returnTRUE;if(((x)==stone_X[j])&&((y-i)==stone_Y[j])){if(stone_vistied[j]==FALSE){stone_vistied[j]=TRUE;check_if_finshed+=jump(jump_power,stone_X[j],stone_Y[j],finish_X,finish_Y);}}}}returncheck_if_finshed;}
raccond
문제에 주어진 샘플 확인시에는 문제가 없는데,
제출하면 오답이 나옵니다.
무엇이 문제일까요...
도움 부탁 드립니다.
감사합니다.
11년 전