Multi-University Training Contest 3 — 1004题
来源:互联网 发布:办公室平台软件 编辑:程序博客网 时间:2024/05/21 05:56
Multi-University Training Contest 3 — 1004题
Painter
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Mr. Hdu is an painter, as we all know, painters need ideas to innovate , one day, he got stuck in rut and the ideas dry up, he took out a drawing board and began to draw casually. Imagine the board is a rectangle, consists of several square grids. He drew diagonally, so there are two kinds of draws, one is like ‘\’ , the other is like ‘/’. In each draw he choose arbitrary number of grids to draw. He always drew the first kind in red color, and drew the other kind in blue color, when a grid is drew by both red and blue, it becomes green. A grid will never be drew by the same color more than one time. Now give you the ultimate state of the board, can you calculate the minimum time of draws to reach this state.
Input
The first line is an integer T describe the number of test cases.
Each test case begins with an integer number n describe the number of rows of the drawing board.
Then n lines of string consist of ‘R’ ‘B’ ‘G’ and ‘.’ of the same length. ‘.’ means the grid has not been drawn.
1<=n<=50
The number of column of the rectangle is also less than 50.
Output
Output an integer as described in the problem description.
Output
Output an integer as described in the problem description.
Sample Input
24RR.B.RG..BRRB..R4RRBBRGGBBGGRBBRR
Sample Output
36
题目大意:在一个网格上画画
行数告诉了
但是列数不确定
可以用strlen来求
求测试数据中隐含的信息
本来是一个空白的网格
在上面作画
必须是斜着往上面撒颜料
只能是从左上方到右下
或者右上到坐下
一笔挥出不能间断
从左上到右下的笔画必须是红色的颜料
右上到坐下必须是蓝色颜料
两种颜色相互融合会变为绿色
现在已知最后这块网格的颜色分布
问最少需要画多少笔能达到现在的效果。
算是一道模拟题吧,从两个不同的角度(左上到右下,右上到坐下)扫描,绿色可以当做红色也可以当做蓝色来判断,记下有多少条连续的颜色段,就是所要的结果。
#include<iostream>
#include<string.h>
using namespace std;
char map[52][52];
int main()
{
int t, hangshu,lieshu;
cin >> t;
while (t--)
{
memset(map, 0, sizeof(map));
cin >> hangshu;
for (int i = 0; i < hangshu; i++)
cin >> map[i];
lieshu=strlen(map[0]);
int s = 0;
for (int i = 0,j=0; i < hangshu ; i++)
{
bool lianxu = false;
for (int ii = i, jj = j; ii < hangshu&&jj < lieshu; ii++, jj++)
{
if (map[ii][jj] == 'R' || map[ii][jj] == 'G')
{
if (lianxu == false)
{
lianxu = true;
s++;
}
}
else
lianxu = false;
}
}
for (int i = 0, j = 1; j < lieshu; j++)
{
bool lianxu = false;
for (int ii = i, jj = j; ii < hangshu&&jj < lieshu; ii++, jj++)
{
if (map[ii][jj] == 'R' || map[ii][jj] == 'G')
{
if (lianxu == false)
{
lianxu = true;
s++;
}
}
else
lianxu = false;
}
}
for (int i = 0, j = 0; j < lieshu; j++)
{
bool lianxu = false;
for (int ii = i, jj = j; ii < hangshu&&jj >= 0; ii++, jj--)
{
if (map[ii][jj] == 'B' || map[ii][jj] == 'G')
{
if (lianxu == false)
{
lianxu = true;
s++;
}
}
else
lianxu = false;
}
}
for (int i = 1, j = lieshu-1; i < hangshu; i++)
{
bool lianxu = false;
for (int ii = i, jj = j; ii < hangshu&&jj >= 0; ii++, jj--)
{
if (map[ii][jj] == 'B' || map[ii][jj] == 'G')
{
if (lianxu == false)
{
lianxu = true;
s++;
}
}
else
lianxu = false;
}
}
cout << s << endl;
}
return 0;
}
- Multi-University Training Contest 3 — 1004题
- 2015 Multi-University Training Contest 3 1004 painter
- Multi-University Training Contest 4 — 1001题
- Multi-University Training Contest 4 — 1002题
- 2012 Multi-University Training Contest 3
- 2013 Multi-University Training Contest 3
- 2013 Multi-University Training Contest 3
- 2014 Multi-University Training Contest 3小记
- 2015 Multi-University Training Contest 3
- 2015 Multi-University Training Contest 3
- 2015 Multi-University Training Contest 3 RGCDQ
- 2015 Multi-University Training Contest 3
- 2015 Multi-University Training Contest 3
- 2015 Multi-University Training Contest 3
- 2016 Multi-University Training Contest 3
- 2015 Multi-University Training Contest 3
- 2016 Multi-University Training Contest 3
- 2016 Multi-University Training Contest 3
- 写给编程语言,虚拟机,优化以及未来之路
- C#的继承特性
- Android 百分比布局库(percent-support-lib) 解析与扩展
- 使用国内镜像通过pip安装python的一些包(转)
- HDOJ 欧拉回路 1878【欧拉回路判定】
- Multi-University Training Contest 3 — 1004题
- Android Fragment数据保存问题
- Multi-University Training Contest 4 — 1001题
- 翁恺导师第1周编程题"设计一个表示分数的Fraction类”--网易云课堂
- js使用正则(简单介绍)
- hibernate 注解
- Android蓝牙串口通信模板及demo,trick
- MySql免安装版l配置方法
- 解析json文件