ZOJ 3780Paint the Grid Again
来源:互联网 发布:尼康固件 镜头数据 编辑:程序博客网 时间:2024/06/01 09:46
倒着来就行 直接模拟
开始没注意逆序,分别用了优先队列,拓补排序都是wa
用优先队列应该时间会少很多
#include<iostream>#include<cstdio>#include<set>#include<string>#include<string.h>#include<cstring>#include<vector>#include<map>#include<queue>#include<stack>#include<cctype>#include<algorithm>#include<sstream>#include<utility>#include<cmath>#define mt(a) memset(a,0,sizeof (a))#define fl(a,b,c) fill(a,b,c)#define SWAP(a,b,t) (t=a,a=b,b=t)#define inf 1000000using namespace std;typedef long long ll;typedef struct node{int val;char type;}node;node ans[1000];char g[600][600];int n;stack<node>s;node cheak(){int flag = 0;node t;t.val = -1;for (int i = n-1; i>=0; i--){flag = 0;for (int j = 0; j < n; j++){if (g[j][i] == 'X'){flag = 0; break;}if (g[j][i] == 'O')flag = 1;}if (flag){t.type = 'C';t.val = i;return t;}}for (int i = n-1; i >=0; i--){flag = 0;for (int j = 0; j < n; j++){if (g[i][j] == 'O'){flag = 0; break;}if (g[i][j] == 'X')flag = 1;}if (flag){t.type = 'R';t.val = i;return t;}}return t;}int main(){int T;cin >> T;while (T--){while (!s.empty())s.pop();scanf("%d", &n);for (int i = 0; i < n; i++){scanf("%s", g[i]);}node temp;while ((temp = cheak()), temp.val != -1){s.push(temp);if (temp.type == 'R'){for (int i = 0; i < n; i++){g[temp.val][i] = 'F';}}else{for (int i = 0; i < n; i++){g[i][temp.val] = 'F';}}}int flag = 1;for (int i = 0; i<n; i++){for (int j = 0; j < n; j++){if (g[i][j] != 'F'){flag = 0; break;}}}if (flag){printf("%c%d", s.top().type, s.top().val + 1);s.pop();while (!s.empty()){printf(" %c%d", s.top().type, s.top().val + 1);s.pop();}printf("\n");}else printf("No solution\n");}return 0;}
0 0
- ZOJ 3780 Paint the Grid Again
- ZOJ 3780 Paint the Grid Again (模拟)
- zoj 3780 Paint the Grid Again
- ZOJ 3780 Paint the Grid Again(topsort)
- zoj 3780 Paint the Grid Again
- ZOJ 3780 Paint the Grid Again
- ZOJ 3780Paint the Grid Again 模拟
- ZOJ 3780Paint the Grid Again
- ZOJ 3780 - Paint the Grid Again
- Paint the Grid Again ZOJ - 3780
- ZOJ 3780 Paint the Grid Again 拓扑排序 策略题
- zoj 3780Paint the Grid Again 拓扑排序
- zoj 3780 Paint the Grid Again (拓扑排序)
- ZOJ 3780 --Paint the Grid Again 逆向自然求解法
- zoj 3780 Paint the Grid Again(拓扑排序)
- ZOJ-3780-Paint the Grid Again【11th浙江省赛】
- ZOJ 3780Paint the Grid Again-贪心模拟/拓扑排序
- ZOJ 3780 Paint the Grid Again (逆推)
- daemon线程总结
- chrome调试less
- 初识Servlet并发处理
- android View 绘制流程
- red5学习日志二
- ZOJ 3780Paint the Grid Again
- 【Android机制】IPC机制之AIDL
- Android上V8 JS引擎
- 计算簇间距离
- LruCache实现原理
- ZOJ 3778Talented Chef
- new balance 574 bybd arbz nooy
- [xxx respondsToSelector:]message sent to deallocated instance和空地址崩溃 空指针
- Groovy 与 DSL