博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1656 Counting Black
阅读量:2440 次
发布时间:2019-05-10

本文共 1887 字,大约阅读时间需要 6 分钟。

Counting Black
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 10360   Accepted: 6691

Description

There is a board with 100 * 100 grids as shown below. The left-top gird is denoted as (1, 1) and the right-bottom grid is (100, 100). 
We may apply three commands to the board: 
1.	WHITE  x, y, L     // Paint a white square on the board,                            // the square is defined by left-top grid (x, y)                           // and right-bottom grid (x+L-1, y+L-1)2.	BLACK  x, y, L     // Paint a black square on the board,                            // the square is defined by left-top grid (x, y)                           // and right-bottom grid (x+L-1, y+L-1)3.	TEST     x, y, L    // Ask for the number of black grids                             // in the square (x, y)- (x+L-1, y+L-1)
In the beginning, all the grids on the board are white. We apply a series of commands to the board. Your task is to write a program to give the numbers of black grids within a required region when a TEST command is applied. 

Input

The first line of the input is an integer t (1 <= t <= 100), representing the number of commands. In each of the following lines, there is a command. Assume all the commands are legal which means that they won't try to paint/test the grids outside the board.

Output

For each TEST command, print a line with the number of black grids in the required region.

Sample Input

5BLACK 1 1 2BLACK 2 2 2TEST 1 1 3WHITE 2 1 1TEST 1 1 3

Sample Output

76

题意:

对于一个100*100棋盘,进行下列三种操作

BLACK x y l  将(x,y)为左上角,边长为l的正方形涂黑

WHITE x y l  将(x,y)为左上角,边长为l的正方形涂白

TEST x y l 问(x,y)为左上角,边长为l的正方形有多少个黑色格子

参考代码:

#include 
#include
using namespace std;#define MAX 100int main(){ int map[MAX][MAX]; int t,x,y,l; char s[20]; while (cin>>t){ memset(map,0,sizeof(map)); while (t--){ cin>>s>>x>>y>>l; if (strcmp(s,"BLACK")==0){ for (int i=x;i
每天水一发~

转载地址:http://ffbqb.baihongyu.com/

你可能感兴趣的文章
RedHat上SSH2的安装和使用(转)
查看>>
安全使用RedHat Linux系统(转)
查看>>
RedHat Enterprise AS4硬盘安装步骤(转)
查看>>
全国第一个高校Linux培训考试中心建立(转)
查看>>
Linux黑客大曝光:Linux安全机密与解决方案(转)
查看>>
Gentoo Linux CD 方式全程安装过程(转)
查看>>
关于Kerberos安装的几个问题(转)
查看>>
Solaris硬盘分区简介(转)
查看>>
gcc编译器小知识FAQ(转)
查看>>
Linux下多线程编程与信号处理易疏忽的一个例子(转)
查看>>
流氓和木马结合 强行关闭你的防火墙(转)
查看>>
SUSE一纸诉状控告SCO 捍卫知识产权(转)
查看>>
debian下编译2.6.13.2内核的步骤及感受(转)
查看>>
预装正版的市场意义(转)
查看>>
创建小于16M XFree86迷你Linux系统(转)
查看>>
shell中常用的工具(转)
查看>>
使用MySQL内建复制功能来最佳化可用性(转)
查看>>
一个比较vista的vista主题for rf5.0fb(转)
查看>>
推荐一款 Linux 上比较漂亮的字体(转)
查看>>
在Linux中添加新的系统调用(转)
查看>>