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

题目很简单,用到的知识点很少,刚刚入门的兄弟可以看一看,用于提高做题信心也好。附代码,供参考~

Posted by ajioy at 2011-07-28 14:49:50 on Problem 1656 and last updated at 2011-07-28 14:52:59
//Accepted 292K 0MS C++ 934B 2011-07-28 14:34:29 
//题目很简单,画个图理解一下就行,代码很好写 
#include <iostream>
using namespace std;
int grid[101][101]={0};///初始化所有grid网格为白色,用0表示

int Calculate(int,int,int);//个人比较喜欢用一个函数来进行运算
int main()
{
	int n,x,y,l,bnum=0;
	char color[10];
    cin>>n;
    while(n--)
    {
    	cin>>color>>x>>y>>l;
    	for(int p=x;p<=x+l-1;p++)
         for(int q=y;q<=y+l-1;q++)
        {
  	  if(!strcmp(color,"WHITE"))
  	  {
  	    grid[p][q]=0;
  	  }
  	  else if(!strcmp(color,"BLACK"))
  	  {
  	    grid[p][q]=1;
  	  }
  	}
          if(!strcmp(color,"TEST"))
  	     {
  	      cout<<Calculate(x,y,l)<<endl;
         } 		   		          	
    }
    return 0;
}

int Calculate(int x,int y,int l)//计算出所有黑网格的数量 
{
	int blackNum=0;
	for(int i=x;i<=x+l-1;i++)
  		   for(int j=y;j<=y+l-1;j++)
  		   {
  		   	if(grid[i][j])
  		   	blackNum++;
  		   }
  		   return blackNum;
}

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