Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题1A,贴个代码

Posted by lx865712528 at 2013-07-24 14:22:09 on Problem 1656
#include<cstdio>
int map[101][101];
void black(int x,int y,int l)
{
	for(int i=x;i<=x+l-1;i++)
	{
		for(int j=y;j<=y+l-1;j++)
		{
			map[i][j]=1;
		}
	}
}
void white(int x,int y,int l)
{
	for(int i=x;i<=x+l-1;i++)
	{
		for(int j=y;j<=y+l-1;j++)
		{
			map[i][j]=0;
		}
	}
}
int test(int x,int y,int l)
{
	int ans=0;
	for(int i=x;i<=x+l-1;i++)
	{
		for(int j=y;j<=y+l-1;j++)
		{
			if(map[i][j]==1)
				ans++;
		}
	}
	return ans;
}
int main()
{
	int x=0,y=0,l=0;
	int i=0,ans=0,t=0;
	char command[6]={""};
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s%d%d%d",command,&x,&y,&l);
		if(command[0]=='B')
			black(x,y,l);
		else if(command[0]=='W')
			white(x,y,l);
		else
		{
			ans=test(x,y,l);
			printf("%d\n",ans);
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator