TOJ 4078 find the princessI(模拟)

来源:互联网 发布:淘宝清洗已过期 编辑:程序博客网 时间:2024/05/20 20:55

4078.   find the princessI
Time Limit: 1.0 Seconds   Memory Limit:65536K
Total Runs: 406   Accepted Runs:140



Nowadays, lots of students enjoy the cellphone game Kupao of Tencent. The story of Kupao is that goddess of Dsir was caught by an evil man and Dsir wants to rescue her of danger.
The operator of Kupao is jump or squat down. However, it is easier for Dsir. The rule is followed:
1: There is a map with two dimensional (x,y). Dsir is on (0,0) an the beginning and he should reach at (100,0) finally.
2: Every thing at the map with 1 length and 1 height include Dsir.
3: There are some blocks at the map and they can floating in the air, but Dsir can not get through.
It is that if there is a block at (1,0), Dsir can not pass without jump.
4: Dsir can only go forward or jump. Eg: if he jump at (0,0) the whole trace is(0,0)->(1,1)->(2,2)->(3,1)->(4,0) and when he jump any block at these place is forbidden.
More clearly see this picture.
5: some blocks may at same place!

Input

A number N indicate the blocks number. N < 100;
Then N lines followed. Each line with two number (x,y) meanings the block’s place.
0 < x < 96 , 0 ≤ y < 3

Output

If Dsir can reach at (100,0) ouput 1, otherwise output 0.

Sample Input

31 01 11 232 02 15 1

Sample Output

01


只需要判断上边两个和下边两个是否联通 


#include<iostream>#include<cstdio>#include<vector>#include<set>#include<algorithm>#include<cmath>#include<cstring>using namespace std;int map[5][120];int main(){int N;while(scanf("%d",&N)!=EOF){memset(map,0,sizeof(map));for(int i=0;i<N;i++){int r,c;scanf("%d %d",&r,&c);map[c][r] = 1;}int flag = 1;for(int i = 1 ; i <= 100 ; i++){//have block if(map[0][i] == 1){//先看是否在范围内if(i-1 >= 0 && i < 100 && i+1 < 100 && i+2 < 100 && i+3 <=100){//再看是否有块if(map[0][i-1]==0 && map[1][i]==0 && map[2][i+1]==0 && map[1][i+2]==0 && map[0][i+3] ==0){//能过continue; }}if(i-2 >= 0 && i-1 < 100 && i < 100 && i+1 < 100 && i+2 <=100){if(map[0][i-2]==0 && map[1][i-1]==0 && map[2][i]==0 && map[1][i+1]==0 && map[0][i+2] ==0){//能过continue; }}if(i-3 >= 0 && i-2 < 100 && i-1 < 100 && i < 100 && i+1 <=100){if(map[0][i-3]==0 && map[1][i-2]==0 && map[2][i-1]==0 && map[1][i]==0 && map[0][i+1] ==0){//能过continue; }}  //过不了flag =0 ;break; }}if(flag == 0)printf("0\n");else printf("1\n");}return 0;} 


阅读全文
0 0
原创粉丝点击