TJU训练赛—A

4078.    find the princessI
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

【分析】
没什么难度的题目...难度全在读题和看图....不需要想太多,想太多容易错,把每个块当成点,就可以直接搜索了,对当前所在的(x,0)位置判断能否到达(x+1,0)或跳起来到达(x+4,0),题目数据保证了x<96也就是不存在可能会跳起来超过100的情况
【代码】
#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值