hdu 5319 - Painter(模拟题)解题报告
2015-08-11 20:09
302 查看
Painter
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1155 Accepted Submission(s): 514
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
2 4 RR.B .RG. .BRR B..R 4 RRBB RGGB BGGR BBRR
Sample Output
3 6
题解:
贪心,分别遍历'/'一遍,'\'一遍即可。
参考代码:
#include<stdio.h> #include<string.h> int main() { int t,ans; char str[55][55]; scanf("%d",&t); while(t--) { ans=0; int n,m; memset(str,0,sizeof(str)); scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%s",str[i]+1); m=strlen(str[1]+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(str[i][j]=='R'||str[i][j]=='G') if(!(str[i-1][j-1]=='R'||str[i-1][j-1]=='G')) ans++; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(str[i][j]=='B'||str[i][j]=='G') if(!(str[i-1][j+1]=='B'||str[i-1][j+1]=='G')) ans++; printf("%d\n",ans); } }
相关文章推荐
- 2015 2015 Multi-University Training Contest 7 hdu 5375
- Rain on your Parade---hdu2389(HK求最大匹配)
- ubuntu 突然不能 sudo成功,报错su: Authentication failure
- No identities are available for signing的解决方法
- socket bind failed解决方案
- 2015 Multi-University Training Contest 7 hdu 5375 Gray code
- Matrix Chain Multiplication
- hdu 4630 No Pain No Game(树状数组)
- 2015 Multi-University Training Contest 7
- [AIR] AS3读取本地文件夹中的文件
- [AIR] AS3读取txt文档
- Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport e
- Container with most water
- main函数中通过使用Person类和AddressBook类,创建对象、调用方法,实现以下8个功能
- Ubuntu下编译运行Kamailio
- AIX开启telnet服务
- POJ 3068 "Shortest" pair of paths(最小费用最大流-mcmf)
- Webmin version 1.760 is now available, but you are running version 1.730.
- 2015 HUAS Summer Trainning #5~A
- Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE的报错的解决方法