HDU-5319 Painter
来源:互联网 发布:ant 打包java指定目录 编辑:程序博客网 时间:2024/05/22 06:50
#include <iostream>#include <cstring>using namespace std;const int maxn = 60;char rec[maxn][maxn];int dict[maxn][maxn];int t, n, m, cnt;//int k = 0;//inline void print()//{// cout << ++k << endl;// for(int i = 0; i < n; i++)// {// for(int j = 0; j < m; j++)// cout << dict[i][j] << " ";// cout << endl;// }// cout << endl;//}int main(void){ bool z = false; int l, r; cin >> t; while(t--) { cin >> n; cnt = 0; for(int i = 0; i < n; i++) cin >> rec[i]; m = strlen(rec[0]); memset(dict,0,sizeof(dict)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if((rec[i][j] == 'R' || rec[i][j] == 'G') && dict[i][j] == 0) { dict[i][j] = 1; l = i + 1, r = j + 1; while(l < n && r < m && dict[l][r] == 0 && (rec[l][r] == 'R' || rec[l][r] == 'G')) { dict[l][r] = 1; l++,r++; } z = true; } if(z) { cnt++; z = false; //print(); } } } memset(dict,0,sizeof(dict)); for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if((rec[i][j] == 'B' || rec[i][j] == 'G') && dict[i][j] == 0) { dict[i][j] = 1; l = i + 1, r = j - 1; while(l < n && r >= 0 && dict[l][r] == 0 && (rec[l][r] == 'B' || rec[l][r] == 'G')) { dict[l][r] = 1; l++,r--; } z = true; } if(z) { cnt++; z = false; //print(); } } } cout << cnt << endl; }}
题意:给一副画,上面分别有三种颜色,红(R)蓝(B)绿(G)(红蓝基础色,绿是红蓝相交后产生。(槽点:红+蓝 = 绿?)),红色只能↖↘画,蓝色只能↙↗画。问最少几笔就能产生这幅画。
题解:从昨天下午2点到今天下午2点。这耗时也是令我心累。总是有点BUG。到最后直接重写反而过。总之是干上了,把南墙撞了才继续前进。(第一次写这道题装比用map做标记,结果map并不是对应数组每个元素对应变化....)
输入t(杭电固有格式),之后输入n(表示输入行数)(只是行数,列数并不确定,也就是题目第一个注意点 不一定是正方形)。(我就不吐槽阿信叠跟我说一定是正方形了。。)第二个注意点就是一笔下去可以中间停下,不一定划到底。如果去掉注释,便可以反映整个画出这幅画的过程。dict数组是为了做标记。就是利用了两个循环,第一个循环针对R和G,只↘这方向画(l++,r++),第二个循环针对B和G,只↙这方向画(l++,r--).(因为是从上到下搜索 所以只要朝这两个方向就能遍历。)。举例第一次循环,先把二维数组全部清零,之后搜索,遇到R和G并且标记值dict==0(说明这个元素之前没有划到过)给其打上标记 (此时cnt++),之后在此循环内部循环,i++ r++遍历对角线(满足没有超过边界 没有被标记过 并且是G或者R)。
0 0
- 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
- HDU - 5319 Painter
- HDU 5319-Painter
- HDU 5319 Painter (模拟 脑洞题)
- hdu 5319 Painter(水)
- 移动H5前端性能优化指南
- 用java做了个控制台版的2048
- 怎么学习一个开源框架
- UE4学习笔记9th
- hdu 5325 Crazy Bobo 拓扑排序
- HDU-5319 Painter
- Python用Bottle轻量级框架进行Web开发
- C# 导入EXCEL 报错外部表不是预期的格式错误
- Oracle 表id实现自增
- Xcode7 不能使用http网络请求
- cereal:C++实现的开源序列化库
- HDU 4006 The kth great number 【队列】
- Android View的onTouchEvent和OnTouch区别
- Robotium之Android控件定位实践和建议(Appium/UIAutomator姊妹篇)