博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[TopCoder][SRM] SRM 562 DIV 2
阅读量:6526 次
发布时间:2019-06-24

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

Problem Statement

    

Cucumber Boy likes drawing pictures. Today, he plans to draw a picture using a very simple graphics editor.

 

The editor has the following functions:

  • The canvas is an infinite two-dimensional grid of pixels.
  • There are only two colors: black, and transparent. These are denoted 'B' and '.' (a period), respectively.
  • The editor has a clipboard that contains a rectangular picture.
  • The editor can take the picture in the clipboard and paste it onto any corresponding rectangle of the canvas. The user just has to select the pixel of the canvas where the upper left corner of the clipboard will be pasted.
  • When pasting the picture, the black pixels of the picture in the clipboard will overwrite their corresponding pixels on the canvas. The pixels that are transparent in the clipboard picture do not change the canvas.

 

At this moment, all pixels on the infinite canvas are transparent. Cucumber Boy has already stored a picture in the clipboard. You are given this picture as a vector <string> clipboard.

 

Cucumber Boy now wants to paste the clipboard picture onto the canvas exactly T times in a row.

For each i, when pasting the clipboard for the i-th time, he will choose the pixel (i,i) as the upper left corner of the pasted picture.

 

You are given the vector <string> clipboard and the int T. Return the number of black pixels on the canvas after all the pasting is finished.

Definition

    
Class: PastingPaintingDivTwo
Method: countColors
Parameters: vector <string>, int
Returns: long long
Method signature: long long countColors(vector <string> clipboard, int T)
(be sure your method is public)
    
 

Constraints

- clipboard will contain between 1 and 50 elements, inclusive.
- Each element of clipboard will contain between 1 and 50 characters, inclusive.
- Each element of clipboard will contain the same number of characters.
- Each character of each element of clipboard will be 'B' or '.'.
- T will be between 1 and 1,000,000,000, inclusive.

Examples

0)  
    
{"..B","B..","BB."}
3
Returns: 10

1)  
    
{"B...","....","....","...B"}
2
Returns: 4
 
2)  
    
{"BBB"}
10000
Returns: 30000
 
3)  
    
{"."}
1000000000
Returns: 0
 
4)  
    
{"BB.",".B."}
100
Returns: 201
 
5)  
    
{"..........B..........",".........B.B.........","........B...B........",".......B.....B.......","......B..B.B..B......",".....B...B.B...B.....","....B...........B....","...B...B.....B...B...","..B.....BBBBBB....B..",".B..........BB.....B.","BBBBBBBBBBBBBBBBBBBBB"}
1000000000
Returns: 21000000071

Note that the answer may overflow a 32-bit integer variable.

 

This is the image of clipboard in this example.

只有在同一对角线的各自会影响到对方,所以按照对角线的方式来遍历每个格子,然后记录每个格子的开始和结束位置,之后做一下处理

1 #include 
2 #include
3 using namespace std; 4 5 class PastingPaintingDivTwo 6 { 7 public: 8 long long calc(vector
clipboard, int T, int x, int y) 9 {10 long long sum = 0;11 int endX = -1;12 int endY = -1;13 while(x < clipboard.size() && y < clipboard[0].size())14 {15 if (clipboard[x][y] == 'B')16 {17 int endCurX = x + T - 1;18 int endCurY = y + T - 1;19 int startCurX = max(x, endX);20 int startCurY = max(y, endY);21 22 sum += max(0, endCurX - startCurX + 1);23 24 endX = max(endCurX + 1, endX);25 endY = max(endCurY + 1, endY);26 }27 28 x++;29 y++;30 }31 32 return sum;33 }34 35 long long countColors(vector
clipboard, int T)36 {37 if (clipboard.size() == 0)38 return 0;39 40 long long sum = 0;41 for(int i = 0; i < clipboard.size(); i++)42 {43 sum += calc(clipboard, T, i, 0);44 }45 46 for(int i = 1; i < clipboard[0].size(); i++)47 {48 sum += calc(clipboard, T, 0, i);49 }50 51 return sum;52 }53 };

 

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

你可能感兴趣的文章
为你的网站加上SSL,可以使用HTTPS进行访问
查看>>
软件project--谈项目开发
查看>>
在Android中创建文件
查看>>
爬虫基础
查看>>
JS组件系列——再推荐一款好用的bootstrap-select组件,亲测还不错
查看>>
getopt--parse command line options
查看>>
闭包和OC的block的本质
查看>>
MySQL出现Waiting for table metadata lock的场景浅析
查看>>
C# 语言历史版本特性(C# 1.0到C# 7.1汇总更新)
查看>>
什么是数据埋点?
查看>>
git回滚
查看>>
vue2.0 引用qrcode.js实现获取改变二维码的样式
查看>>
Python 判断闰年,判断日期是当前年的第几天
查看>>
web.xml 中的listener、 filter、servlet 加载顺序
查看>>
MyBatis原理简介和小试牛刀
查看>>
js部分基础
查看>>
脏读,幻读,不可重复读解释和例子
查看>>
Tomcat指定(JDK路径)JAVA_HOME而不用环境变量
查看>>
银行卡信息安全事件频发 互联网站成数据泄露"重灾区"
查看>>
云服务器 ECS 使用OpenAPI管理ECS:使用OpenAPI弹性创建ECS实例
查看>>