Painter
来源:互联网 发布:如何优化搜索引擎 编辑:程序博客网 时间:2024/05/16 05:51
Painter
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2221 Accepted Submission(s): 885
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.
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
Author
ZSTU
Source
2015 Multi-University Training Contest 3
题目也是看了几遍看懂,大意:红色 ‘\’ 方向涂色,蓝色 '/'方向涂色,红蓝交差成绿色,还有一个地方要仔细“Imagine the board is a rectangle,”输入是可以为矩形的,之前没看仔细,看的案例一直以为是正方形导致了多次WA。
代码如下:
题目也是看了几遍看懂,大意:红色 ‘\’ 方向涂色,蓝色 '/'方向涂色,红蓝交差成绿色,还有一个地方要仔细“Imagine the board is a rectangle,”输入是可以为矩形的,之前没看仔细,看的案例一直以为是正方形导致了多次WA。
代码如下:
#include<cstdio>#include<cstring>#include<cctype>#include<algorithm>#include<set>#include<cstring>#include<string>#include<iostream>using namespace std;char a[100][100];int n;void f(int i,int j,char c){ /*if(i>=n||j>=n||i<0||j<0) return ;*///这里之前误以为正方形 从而导致结束条件的错误 if(a[i][j]=='.') return ; if(a[i][j]!=c&&a[i][j]!='G') return ; if(a[i][j]==c) a[i][j]='.'; else if(a[i][j]=='G') { if(c=='R') a[i][j]='B'; else if(c=='B') a[i][j]='R'; } if(c=='R') f(i+1,j+1,c); else if(c=='B') f(i+1,j-1,c);}int main (){ int t; scanf("%d",&t); while(t--){ scanf("%d",&n); // getchar(); memset(a,0,sizeof(a)); for(int i=0;i<n;i++){ scanf("%s",a[i]);//用%s输入一个字符串,之前以为是正方形,于是用了两个for循环 %c一个个输。 } int n1=strlen(a[0]);//取矩形的宽度 int ans=0; for(int i=0;i<n;i++) for(int j=0;j<n1;j++){ if(a[i][j]=='R') { ans++; f(i,j,'R'); } else if(a[i][j]=='B') { ans++; f(i,j,'B'); } else if(a[i][j]=='G') { ans+=2; f(i,j,'R'); f(i,j,'B'); } } printf("%d\n",ans); }}
阅读全文
0 0
- Painter
- Painter
- Painter (p2709)
- poj2709 Painter
- HDU5319.Painter
- hdu5319 Painter
- hdu5319 Painter
- String painter
- HDU5319 Painter
- 【POJ】Painter
- String painter
- String painter
- .NET System Brushes Painter
- POJ 2709 Painter
- poj 2709 Painter
- Painter's Problem POJ1681
- hdoj 2476 String painter
- HDU2476(String painter)DP
- android重点总结
- 改变静态编辑框static text背景色,字体设置及字体背景
- JavaScript学习笔记之js实现复选框checkbox的全选、反选示例
- Python 脚本在后台运行
- struts1中radio list的默认值设置和value保持
- Painter
- [Leetcode] 280. Wiggle Sort 解题报告
- javascript
- Vim技能修炼教程(5)
- Python :链表中环的入口节点
- DataGridView绑定数据源后,在界面上删除行,数据源没有改变
- “AF_IPX”: 宏重定义的解决方法
- spring-boot学习笔记1
- Java学习 Number类 Charracter类