您的位置:首页 > 其它

ZOJ 2850和ZOJ 1414

2013-09-10 18:37 309 查看
下午上数据结构,结果竟然没有新题。T T果断上OJ来水一发

ZOJ 2850 Beautiful Meadow

传送门http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2850

题目判断yes的条件为

不是所有的格子都是草地,并且相邻不能没有草地。

#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=12;
int area[MAXN][MAXN];
int N,M;

bool ok()
{
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<M;j++)
			{
				
			//	cout<<area[i][j]<<" "<<area[i+1][j]<<endl;
		
					if(i>0 && area[i-1][j]==0 && area[i][j]==0)
						return 0;
					if(j>0 && area[i][j-1]==0 && area[i][j]==0)
						return 0;
					if(i<N-1 && area[i+1][j]==0 && area[i][j]==0)
						return 0;
					if(j<M-1 && area[i][j+1]==0 && area[i][j]==0)
						return 0;

			}
		
		}
		return true;
}

int main()
{

	while(scanf("%d%d",&N,&M),N||M)
	{
		bool allone=true;

		for(int i=0;i<N;i++)
		{
			for(int j=0;j<M;j++)
			{
				scanf("%d",&area[i][j]);
				if(area[i][j]==0)
					allone=false;
			}
		}

		if( !allone && ok())
			printf("Yes\n");
		else 
			printf("No\n");
	}
}


ZOJ 1414 Number Steps

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1414

找x和y的关系就好

#include<cstdio>
int main()
{
	int N;
	scanf("%d",&N);
	while(N--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x-y==2 || x==y)
		{
			if(x%2==0)
				printf("%d\n",x+y);
			else 
				printf("%d\n",x+y-1);

		}
		else 
			printf("No Number\n");
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: