HDU 5319(2015多校3)-Painter(dfs)
来源:互联网 发布:ubuntu服务器密码修改 编辑:程序博客网 时间:2024/05/29 09:58
题目地址:HDU 5319
题意:给一个图n*m,原来全是点(’.’)。 现在要把图染成已给出的样子。 要求当是’\’的情况只用红色,是’/’的情况只用蓝色,当一个格子同时被红色和蓝色染得时候变成绿色。(每个格子只画一次)。
思路:这题只要模拟一下刷的过程就行了,如果出现了R,就刷R刷到底,出现B就刷B,出现G就左右各刷一次。
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>//#pragma comment(linker, "/STACK:102400000,102400000")using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);const double esp=1e-8;char str[60][60];int n,m;void dfs_R(int x, int y) { if (x>=0&&x<n&&y>=0&&y<m&&(str[x][y]=='R'||str[x][y]=='G')) { if (str[x][y]=='G') str[x][y]='B'; else str[x][y]='.'; dfs_R(x-1,y-1); dfs_R(x+1,y+1); } return ;}void dfs_B(int x, int y) { if(x>=0&&x<n&&0<=y&&y<m&&(str[x][y]=='B'||str[x][y]=='G')) { if(str[x][y]=='G') str[x][y]='R'; else str[x][y]='.'; dfs_B(x+1,y-1); dfs_B(x-1,y+1); } return ;}int main() { int T; int cnt; scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=0; i<n; i++) scanf("%s",str[i]); m=strlen(str[0]); cnt=0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (str[i][j]=='R') { dfs_R(i, j); cnt++; } else if (str[i][j]=='B') { dfs_B(i, j); cnt++; } else if (str[i][j]=='G') { dfs_R(i, j); str[i][j]='B'; dfs_B(i, j); cnt+= 2; } } } printf("%d\n",cnt); } return 0;}
1 0
- HDU 5319(2015多校3)-Painter(dfs)
- hdu 5319 Painter(DFS)
- hdu 5319 Painter 2015 Multi-University Training Contest 3
- hdu 5319 Painter 2015 Multi-University Training Contest 3
- HDU 5319 Painter
- hdu 5319 Painter
- HDU 5319 Painter(模拟)
- HDU 5319 Painter
- HDU-5319 Painter
- HDU 5319 Painter(枚举)
- HDU 5319 Painter
- hdu 5319 Painter
- HDU 5319 Painter
- HDU 5319(Painter-暴力)
- HDU 5319 Painter
- HDU 5319 Painter
- Hdu 5319 Painter (模拟)
- HDU 5319 Painter
- oracle 中如何获取本机ip地址,根据IP地址获取域名?
- html中设置锚点定位的几种常见方法
- 九度oj 1087
- 线段树入门
- 小白学开发(iOS)OC_ id类型(2015-07-28)
- HDU 5319(2015多校3)-Painter(dfs)
- 欢迎使用CSDN-markdown编辑器
- LeetCode || Spiral Matrix II
- VB.NET的拖放操作
- 继承,特质
- Nginx+PHP+Swfupload 上传大文件
- centos 7下安装配置nginx
- xUtils 中 HttpUtils 的使用
- ConvertToTable(from Poco class to Table)