UVA1423 Guess!
来源:互联网 发布:易语言我的世界源码 编辑:程序博客网 时间:2024/06/11 09:49
吞噬一切的虫洞
这道题我们可以通过给定的正负关系求出来各个和的大小关系,然后把S当成一个点,大小关系当成有向边,这样通过求一个拓扑序我们就可以得到一个大小关系,然后直接通过大小关系进行赋值,最后通过a[i] = S[i] - S[i - 1]求得原序列元素。(S[i]是前i项和……)
#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;const int N = 15;int dg[N], map[N][N], ans[N], n;char ss[N * N];void init(){memset(map, 0, sizeof(map));memset(dg, 0, sizeof(dg));memset(ans, 0, sizeof(ans));}void topsort(){queue<int> Q;for (int i = 0; i <= n; i++)if (!dg[i]) Q.push(i);int cnt = 0;while(!Q.empty()){int u = Q.front();Q.pop();cnt += 1;for (int i = 0; i <= n; i++){if (map[u][i]){dg[i] -= 1;if (!dg[i]){Q.push(i);ans[i] = cnt;}}}}}int main(){int cs;scanf("%d", &cs);while(cs--){scanf("%d", &n);scanf(" %s", ss);init();int h = 0;for (int i = 1; i <= n; i++)for (int j = i; j <= n; j++){if (ss[h] == '+') {map[i - 1][j] = 1; dg[j] += 1;}if (ss[h] == '-') {map[j][i - 1] = 1; dg[i - 1] += 1;}h += 1;}topsort();for (int i = 1; i < n; i++)printf("%d ", ans[i] - ans[i - 1]);printf("%d\n", ans[n] - ans[n - 1]);}return 0;}
- UVA1423 Guess!
- uva1423
- Guess
- guess
- uva1423(拓扑排序)
- uva1423 拓扑排序
- UVA1423-(拓扑排序)
- LA 4255 UVa1423 拓扑排序
- UVA1423 猜序列 解题报告
- Guess LA4255
- config.guess
- Number-Guess
- A: Guess
- 隐写术-guess
- Guess UVA
- UValive4255 Guess
- Guess My Number!!!
- Guess My Word
- Web Analysis, Vul Assessment & Exploitation using Backtrack5
- Ubuntu设置环境变量
- 关于Pattern 的split()方法
- 算菜价
- 让你的 Qt 桌面程序看上去更加 native(六):跨平台技术
- UVA1423 Guess!
- 让你的 Qt 桌面程序看上去更加 native(五):QDialog
- 编程修养
- HttpRequest对象属性详解
- IDC分析师关于中国大数据市场的十大预测
- 让你的 Qt 桌面程序看上去更加 native(四):style sheet
- Maximal Rectangle
- 9patch图的尺寸尽量为偶数
- POJ1006: 中国剩余定理的完美演绎