Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 400 Accepted Runs: 137
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
3 1 0 1 1 1 2 3 2 0 2 1 5 1
Sample Output
0 1
【分析】
#include <stdio.h>
#include <string.h>
using namespace std;
int vis[110][10];
int flag;
int f[110];
void dfs(int x)
{
if (x==100) flag=0;
if (f[x]||!flag) return;
f[x]=1;
if (!vis[x+1][0]) dfs(x+1);
if (!vis[x+1][1]&&!vis[x+2][2]&&!vis[x+3][1]&&!vis[x+4][0]) dfs(x+4);
}
int main()
{
int n;
while (~scanf("%d",&n))
{
flag=1;
memset(vis,0,sizeof(vis));
memset(f,0,sizeof(f));
for (int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
vis[x][y]=1;
}
dfs(0);
if (flag) puts("0");
else puts("1");
}
return 0;
}