HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3
来源:互联网 发布:知乎三国和战国 编辑:程序博客网 时间:2024/05/21 21:02
传送门
Painter
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1946 Accepted Submission(s): 777
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
2
4
RR.B
.RG.
.BRR
B..R
4
RRBB
RGGB
BGGR
BBRR
Sample Output
3
6
题目大意:
首先给了
的矩阵(
只能用”\”和”/”两种方式涂,让你求从初始状态到达最终状态最少需要几步。其
中”\”这个方向的是涂红色。”/”这个方向的是涂蓝色。
解题思路:
就是暴力来找,假如说我们用 “\” 的方式来涂色,我们需要找到那个开头,也就是假
设
这个方式来涂色也是一样的道理。
/**2016 - 08 - 24 下午Author: ITAKMotto:今日的我要超越昨日的我,明日的我要胜过今日的我,以创作出更好的代码为目标,不断地超越自己。**/#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <vector>#include <queue>#include <algorithm>#include <set>using namespace std;typedef long long LL;typedef unsigned long long ULL;const int INF = 1e9+5;const int MAXN = 1e2+5;const int MOD = 1e9+7;const double eps = 1e-7;const double PI = acos(-1);using namespace std;LL Scan_LL()///输入外挂{ LL res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}int Scan_Int()///输入外挂{ int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res;}void Out(LL a)///输出外挂{ if(a>9) Out(a/10); putchar(a%10+'0');}int a[MAXN][MAXN];char str[MAXN][MAXN];int main(){ int T; T = Scan_Int(); while(T--) { int m; m = Scan_Int(); for(int i=0; i<m; i++) scanf("%s",str[i]); int n = strlen(str[0]); memset(a, 0, sizeof(a)); for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { if(str[i][j] == 'R') a[i+1][j+1] = 1; else if(str[i][j] == 'B') a[i+1][j+1] = 2; else if(str[i][j] == 'G') a[i+1][j+1] = 3; else a[i+1][j+1] = 0; } } int sum = 0; for(int i=1; i<=m; i++) { for(int j=1; j<=n; j++) { if(a[i][j]==3 || a[i][j]==1) { if(!(a[i-1][j-1]==3 || a[i-1][j-1]==1)) sum++; } } } for(int i=1; i<=m; i++) { for(int j=1; j<=n; j++) { if(a[i][j]==3 || a[i][j]==2) { if(!(a[i-1][j+1]==3 || a[i-1][j+1]==2)) sum++; } } } printf("%d\n",sum); } return 0;}
0 0
- HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3
- hdu 5319 Painter 2015 Multi-University Training Contest 3
- hdu 5319 Painter 2015 Multi-University Training Contest 3
- HDU 5319 Painter (2015 Multi-University Training Contest 3 2015多校联合)
- HDU 5399 Too Simple(数学 + 找规律)——2015 Multi-University Training Contest 9
- HDU 5373 The shortest problem(模拟)——2015 Multi-University Training Contest 7
- HDU 5387 Clock(简单模拟)——2015 Multi-University Training Contest 8
- 2015 Multi-University Training Contest 3 1004 painter
- HDU 5826 physics(积分 找规律)——2016 Multi-University Training Contest 8
- HDU 6038 Function(找规律)——2017 Multi-University Training Contest
- HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest
- HDU 5351 MZL's Border(大数 + 找规律)——2015 Multi-University Training Contest 5
- hdu 5831 Rikka with Parenthesis II(2016 Multi-University Training Contest 8——模拟)
- HDU 5754 Life Winner Bo(找规律 + 威佐夫博弈)--2016 Multi-University Training Contest 3
- HDU 5795 A Simple Nim(SG打表找规律)——2016 Multi-University Training Contest 6
- HDU 5810 Balls and Boxes(打表找规律)——2016 Multi-University Training Contest 7 1002
- hdu 6038 找规律 置换 2017 Multi-University Training Contest
- HDU 5288 OO’s Sequence(数学)——2015 Multi-University Training Contest 1
- Radix-2 Iterative-FFT
- 社会统计分析—统计推断-估值
- 子线程 run() 函数中,调用其他函数
- Spring中自动任务的实现
- 深入了解C++继承
- HDU 5319 Painter(模拟 + 规律)——2015 Multi-University Training Contest 3
- 怎样用conda安装opencv
- python从零开始学习(三)--os模块
- HTTP缓存
- Hibernate中用到联合主键的使用方法,为何要序列化,为何要重写hashcode 和 equals 方法
- POJ 1376 Robot(BFS)
- AC自动机水题
- NSIndexSet基本用法
- 二维数组中的查找