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

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

代码如下:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. const int MAX_N = + ;
  7. int map[MAX_N][MAX_N];
  8.  
  9. int Solve(int n, int m)
  10. {
  11. // m 表示行, n表示列数
  12. int count = ;
  13. bool flag = false;
  14. for (int k = m - ; k >= - n; -- k)
  15. {
  16. flag = false;
  17. for (int j = ; j < n; ++ j)
  18. {
  19. int i = j + k;
  20. if ( <= i && i < m && <= j && j < n)
  21. {
  22. if (map[i][j] & )
  23. {
  24. map[i][j] = map[i][j] - ;
  25. if (!flag)
  26. {
  27. flag = true;
  28. count++;
  29. }
  30. } else if ((map[i][j] & ) == && flag)
  31. flag = false;
  32. }
  33. }
  34. }
  35. flag = false;
  36. int t = m + n;
  37. for (int k = ; k < t; ++ k)
  38. {
  39. flag = false;
  40. for (int j = ; j < n; ++ j)
  41. {
  42. int i = -j + k;
  43. if ( <= i && i < m && <= j && j < n)
  44. {
  45. if (map[i][j] & )
  46. {
  47. map[i][j] = map[i][j] - ;
  48. if (!flag)
  49. {
  50. flag = true;
  51. count++;
  52. }
  53. } else if ((map[i][j] & ) == && flag)
  54. flag = false;
  55. }
  56. }
  57. }
  58. return count;
  59. }
  60.  
  61. int main()
  62. {
  63. int case_times;
  64. char str[MAX_N];
  65. int n, m;
  66.  
  67. scanf("%d", &case_times);
  68. while (case_times--)
  69. {
  70. scanf("%d", &n);
  71. memset(map, , sizeof(map));
  72. for (int i = ; i < n; ++ i)
  73. {
  74. scanf("%s", str);
  75. int len = m = strlen(str);
  76. for (int j = ; j < len; ++ j)
  77. {
  78. if (str[j] == '.')
  79. map[i][j] = ;
  80. if (str[j] == 'R')
  81. map[i][j] = ;
  82. if (str[j] == 'B')
  83. map[i][j] = ;
  84. if (str[j] == 'G')
  85. map[i][j] = ;
  86. }
  87. }
  88.  
  89. int ans = Solve(m, n);
  90. printf("%d\n", ans);
  91.  
  92. }
  93. return ;
  94. }

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. 将以管理员方式运行cmd运行方式放到win7任务栏

    首先在桌面空白地方(没有桌面图标位置),点击鼠标右键,选择新建--快捷方式,如下图:       弹出创建快捷方式窗口,输入cmd.exe的路径及文件名,下图是天缘的Windows 7安装到C盘对应的 ...

  2. Android 如何修改自动同步数据的默认开关 M

    前言          欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处:          CSDN:http://www.csdn.net        ...

  3. xHTML+div布局:三个div,两边div宽度固定,中间div宽度自适应

    xHTML+div经常考题:三个div,两边div宽度固定,中间div宽度自适应. 和大家分享一个实现方式: 1.html代码 <div class="dyleft"> ...

  4. Android GreenDao with Android Studio IDE

    转:http://blog.surecase.eu/using-greendao-with-android-studio-ide/ In this tutorial we will show you ...

  5. css3中动画animation的应用

    <!DOCTYPE html> <html> <head> <style> /* @-webkit-keyframes anim1 { // 规定动画. ...

  6. Pthon MySQLdb 的安装

    说明: 要用python 去连接MySQL我们需要一个驱动程序这个程序就是MySQL-python,所以我们首先就是要下一个对应版本的MySQL-python (注意这个驱动程序只有32位版本的,所以 ...

  7. Oracle EBS-SQL (SYS-4):sys_职责查询.sql

    select t.RESPONSIBILITY_NAME from apps.FND_RESPONSIBILITY_VL t where t.RESPONSIBILITY_NAME like '%MR ...

  8. Spring Boot的启动器Starter详解

    Spring Boot的启动器Starter详解 作者:chszs,未经博主允许不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs Spring Boot ...

  9. Http 请求头中的 Proxy-Connection

    平时用 Chrome 开发者工具抓包时,经常会见到 Proxy-Connection 这个请求头.之前一直没去了解什么情况下会产生它,也没去了解它有什么含义.最近看完<HTTP 权威指南> ...

  10. 深入分析MFC文档视图结构(项目实践)

    k_eckel:http://www.mscenter.edu.cn/blog/k_eckel 文档视图结构(Document/View Architecture)是MFC的精髓,也是Observer ...