hdu5319 Painter
来源:互联网 发布:js 特殊字符校验 编辑:程序博客网 时间:2024/06/05 08:04
直接模拟 要非常细心。。。。
代码:
#include <algorithm>#include <iostream>#include <sstream>#include <cstdlib>#include <cstring>#include <iomanip>#include <cstdio>#include <string>#include <bitset>#include <vector>#include <queue>#include <stack>#include <cmath>#include <list>#include <map>#include <set>#define sss(a,b,c) scanf("%d%d%d",&a,&b,&c)#define mem1(a) memset(a,-1,sizeof(a))#define mem(a) memset(a,0,sizeof(a))#define ss(a,b) scanf("%d%d",&a,&b)#define s(a) scanf("%d",&a)#define p(a) printf("%d\n", a)#define INF 0x3f3f3f3f#define w(a) while(a)#define PI acos(-1.0)#define LL long long#define eps 10E-9#define N 100000#define mod 100000000using namespace std;void mys(int& res){ int flag=0; char ch; while(!(((ch=getchar())>='0'&&ch<='9')||ch=='-')) if(ch==EOF) res=INF; if(ch=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; res=flag?-res:res;}void myp(int a){ if(a>9) myp(a/10); putchar(a%10+'0');}/*************************THE END OF TEMPLATE************************/char str[55][55];int solve(int n, int len){ int i, j, k; bool f; int ans1 = 0; /**************求'\R'方式*****************/ for(i = n; i>0; i--){ f = true; for(j = i, k = 1; j<=n && k<= len; j++, k++ ){ if(str[j][k] == 'R' || str[j][k] == 'G'){ f = false ; } if(!f && (str[j][k]!='R' && str[j][k] != 'G')){ ans1 ++; f = true; } } if(!f) ans1++; } for(int j=2; j<=len; j++){ f = true; for(i = 1, k = j; i<=n && k<= len; i++, k++ ){ if(str[i][k] == 'R' || str[i][k] == 'G'){ f = false ; } if(!f && (str[i][k]!='R' && str[i][k] != 'G')){ ans1 ++; f = true; } } if(!f) ans1++; } /**************求'/B'方式*****************/ int ans2 = 0; for(int i= 1; i<=len; i++){ f = true; for(int j = i, k =1; j>0 && k<=n; k++, j--){ if(str[k][j] == 'B' || str[k][j] == 'G'){ f = false; } if(!f && (str[k][j]!='B' && str[k][j] != 'G')){ ans2 ++; f = true; } } if(!f) ans2++; } for(int i= 2; i<=n; i++){ f = true; for(int j = i, k =len; j<=n && k>0; k--, j++){ if(str[j][k] == 'B' || str[j][k] =='G'){ f = false; } if(!f && (str[j][k]!='B' && str[j][k] != 'G')){ ans2 ++; f = true; } } if(!f) ans2++; } return ans1 + ans2;}int main(){ int t, n; s(t); w(t--){ s(n); for(int i=1; i<=n; i++){ scanf("%s", str[i] + 1); } int len = strlen(str[1] + 1); int ans = solve(n, len); cout<<ans<<endl; } return 0;}
1 0
- HDU5319.Painter
- hdu5319 Painter
- hdu5319 Painter
- HDU5319 Painter
- hdu5319 Painter(模拟)
- hdu5319 Painter(模拟)
- HDU5319 Painter(深搜DFS)
- hdu5319 Painter(模拟题)
- 解题报告 之 HDU5319 Painter
- hdu5319(2015多校3)--Painter(暴力,,,)
- 2015多校联合训练第三场Painter(hdu5319)
- HDU5319
- Painter
- Painter
- hdu5319(模拟)
- 问题链接:HDU5319 Painter。 本题可以使用深度优先搜索求解。 红色刷子("R"刷子)按“\”的方向刷,蓝色刷子("B"刷子)按"/"方向刷。一个地方如果被两次刷到变成绿色("G"色)。
- hdu5319 模拟水题
- hdu5319 简单模拟
- 微软沈向洋:计算机视觉未来在语义层 “两大一精”是关键
- 机试算法讲解: 第49题 动态规划之最长递增子序列问题
- 【练习笔记】剑指offer-面试题7 :用两个栈实现队列
- Cocos2d-x_C++11新特性Lambda表达式
- Matlab中varargin函数
- hdu5319 Painter
- malloc(0)
- 机试算法讲解:第50题 动态规划之拦截导弹
- poj-3083 Children of the Candy Corn-DFS+BFS
- leetcode--Kth Smallest Element in a BST
- 多线程(join和yield)
- Lucene七(搜索)
- Servlet学习
- NYOJ269VF【dp】