UVA 1423 - Guess(拓扑排序)
来源:互联网 发布:矩阵扰动 编辑:程序博客网 时间:2024/04/30 14:59
UVA 1423 - Guess
题目链接
题意:给定一个每个区间和的正负,构造一个序列,使得满足这个矩阵
思路:每个区间和等于两个前缀和的差,这样就可以知道每两个前缀和的大小关系,利用拓扑排序可以求出顺序,然后对应要控制不超过|10|,所以从-10开始,大的就+1,然后构造出这个前缀和序列,对应每个ai就等于c[i] - c[i - 1]
代码:
#include <cstdio>#include <cstring>#include <vector>#include <queue>using namespace std;int t, n, du[15], ans[15], tmp[15], tn;char str[105];vector<int> g[15];queue<int> Q;int main() {scanf("%d", &t);while (t--) {scanf("%d%s", &n, str);int sn = 0;while (!Q.empty()) Q.pop();for (int i = 0; i <= n; i++) {du[i] = 0;g[i].clear();}for (int i = 1; i <= n; i++) {for (int j = i; j <= n; j++) {if (str[sn] == '+') {g[i - 1].push_back(j);du[j]++;}else if (str[sn] == '-') {g[j].push_back(i - 1);du[i - 1]++;}sn++;}}for (int i = 0; i <= n; i++)if (du[i] == 0) Q.push(i);int cnt = -10;while (!Q.empty()) {tn = 0;while (!Q.empty()) {tmp[tn] = Q.front();ans[tmp[tn]] = cnt;tn++;Q.pop();}for (int i = 0; i < tn; i++) {int u = tmp[i];for (int j = 0; j < g[u].size(); j++) {du[g[u][j]]--;if (du[g[u][j]] == 0)Q.push(g[u][j]);}}cnt++;}for (int i = 1; i <= n; i++) {printf("%d%c", ans[i] - ans[0] - (ans[i - 1] - ans[0]), i == n ? '\n' : ' ');}}return 0;}
1 0
- UVa 1423 Guess (拓扑排序)
- UVA 1423 - Guess(拓扑排序)
- UVA 1423Guess 【拓扑排序】
- UVA 1423 Guess 拓扑排序
- UVA 1423 Guess(拓扑排序)
- uva-1423Guess 拓扑排序
- uva 1423 - Guess(拓扑排序)
- uva 1423 - Guess(拓扑排序)
- UVA 1423 - Guess(前缀和之差+拓扑排序)
- UVALive4255-Guess(拓扑排序)
- uva 1423 拓扑排序
- LA4255 Guess (拓扑排序)
- UVALive 4255 Guess【拓扑排序 】
- UVALive 4255-Guess-拓扑排序
- LA 4255 Guess 拓扑排序
- uva La 4255 Guess (拓扑排列)
- UValive 4255 Guess(拓扑排序)
- UA 4255 Guess (拓扑排序)
- 北大ACM试题分类 - 实时更新我所有的解题报告链接
- NHibernate记录
- ios block初级使用
- DSP6000的上电及供电
- jquery flot 在节点上显示提示
- UVA 1423 - Guess(拓扑排序)
- NIO组件Selector调用实例
- Mat, vector<point2f>,Iplimage等等常见类型转换
- 上位机与PLC通讯及OPC数据采集实践一
- 在openshift上构建自己的应用
- How to Find the Offending SQL from a ORA-600 or ORA-7445 Trace File (文档 ID 154170.1)转到底部 In this
- 由集成电流传感器MAX471构成±3A电流监测仪的电路
- 读书札记-2013年12月
- DSP6000的几个简单优化技巧