题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319

思路分析:假设颜色R表示为1,颜色B表示为2,颜色G表示为3,因为数据量较小,采用暴力解法即可,即每次扫描对角线,看每条对角线需要画多少笔,统计所有对角线的笔数和即可;

代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std; const int MAX_N = + ;
int map[MAX_N][MAX_N]; int Solve(int n, int m)
{
// m 表示行, n表示列数
int count = ;
bool flag = false;
for (int k = m - ; k >= - n; -- k)
{
flag = false;
for (int j = ; j < n; ++ j)
{
int i = j + k;
if ( <= i && i < m && <= j && j < n)
{
if (map[i][j] & )
{
map[i][j] = map[i][j] - ;
if (!flag)
{
flag = true;
count++;
}
} else if ((map[i][j] & ) == && flag)
flag = false;
}
}
}
flag = false;
int t = m + n;
for (int k = ; k < t; ++ k)
{
flag = false;
for (int j = ; j < n; ++ j)
{
int i = -j + k;
if ( <= i && i < m && <= j && j < n)
{
if (map[i][j] & )
{
map[i][j] = map[i][j] - ;
if (!flag)
{
flag = true;
count++;
}
} else if ((map[i][j] & ) == && flag)
flag = false;
}
}
}
return count;
} int main()
{
int case_times;
char str[MAX_N];
int n, m; scanf("%d", &case_times);
while (case_times--)
{
scanf("%d", &n);
memset(map, , sizeof(map));
for (int i = ; i < n; ++ i)
{
scanf("%s", str);
int len = m = strlen(str);
for (int j = ; j < len; ++ j)
{
if (str[j] == '.')
map[i][j] = ;
if (str[j] == 'R')
map[i][j] = ;
if (str[j] == 'B')
map[i][j] = ;
if (str[j] == 'G')
map[i][j] = ;
}
} int ans = Solve(m, n);
printf("%d\n", ans); }
return ;
}

hdoj 5319 Painter(模拟题)的更多相关文章

  1. 模拟+思维 HDOJ 5319 Painter

    题目传送门 /* 题意:刷墙,斜45度刷红色或蓝色,相交的成绿色,每次刷的是连续的一段,知道最终结果,问最少刷几次 模拟+思维:模拟能做,网上有更巧妙地做法,只要前一个不是一样的必然要刷一次,保证是最 ...

  2. HDU 5319 Painter (模拟)

    题意: 一个画家画出一张,有3种颜色的笔,R.G.B.R看成'\',B看成'/',G看成这两种的重叠(即叉形).给的是一个矩阵,矩阵中只有4种符号,除了3种颜色还有'.',代表没有涂色.问最小耗费多少 ...

  3. poj 1008:Maya Calendar(模拟题,玛雅日历转换)

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64795   Accepted: 19978 D ...

  4. poj 1888 Crossword Answers 模拟题

    Crossword Answers Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 869   Accepted: 405 D ...

  5. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  6. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  7. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  8. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  9. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

随机推荐

  1. js 全局变量

    使用cookies可以设置全局变量 ,由于每次刷新变量都会为初始值,cookies可以作为全局变量的容器

  2. private、 protected、 public、 internal 修饰符的访问权限

    private : 私有成员, 在类的内部才可以访问. protected : 保护成员,该类内部和继承类中可以访问. public : 公共成员,完全公开,没有访问限制. internal: 当前程 ...

  3. React和Angular

    React和Angular 你若装逼,请带我飞! 从前,从前,听说React只负责UI,话说写Angular代码就像写后端,现在看来,React赢在情怀上了: 我认为没必要老是拿React和Angul ...

  4. log4j.xml 为什么要使用SLF4J而不是Log4J

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration SY ...

  5. Android 模拟系统事件(三)

    简介 Android系统是基于Linux内核的,而Linux内核继承和兼容了丰富的Unix系统进程间通信(IPC)机制.Binder其实也不是Android提出来的一套新的进程间通信机制,它是基于Op ...

  6. overfllow的解析

    参数是scroll时候,必会出现滚动条.参数是auto时候,子元素内容大于父元素时出现滚动条.参数是visible时候,溢出的内容出现在父元素之外.参数是hidden时候,溢出隐藏.

  7. _.remove的用法

    var array = [1, 2, 3, 4]; var evens = _.remove(array, function(n) { return n % 2 == 0; }); console.l ...

  8. android基础5——使用资源

    Android会基于当前的硬件.设备和语言配置来为某个资源标识符选择最合适的值. 1.在代码中使用资源 使用静态类R来访问资源.R类是基于外部资源而生的类,并且是在项目编译的时候创建的.R的每一个子类 ...

  9. Android中进行流量统计

    // ---------------------流量统计-------------------------------- try { PackageManager pm = getPackageMan ...

  10. android-supporting-multiple-devices

    There are a few common questions asked whenever development begins on a new Android app. What assets ...