LA 4255(p309)----Guess
来源:互联网 发布:linux内网建站 编辑:程序博客网 时间:2024/05/02 04:44
#include<bits/stdc++.h>#define debuusing namespace std;const int INF=99999;struct point{ int x,y; point(int a=0,int b=0):x(a),y(b) {}};const int maxn=15;char st[60];stack<int> s;int d[maxn];int n,sum[maxn];vector<point> tmp;int g[maxn][maxn];void make(){ tmp.clear(); int num=0; memset(d,0,sizeof(d)); for(int i=0; i<n; i++) { for(int j=i+1; j<=n; j++) { if(st[num]=='+') { g[j][i]=1; d[i]++; } if(st[num]=='-') { g[i][j]=1; d[j]++; } if(st[num]=='0') tmp.push_back(point(i,j)); num++; } }}void solve(){ while(!s.empty()) s.pop(); for(int i=0; i<=n; i++) if(d[i]==0) s.push(i); int tot=11; while(!s.empty()) { int u=s.top(); sum[u]=tot; tot--; s.pop(); for(int i=0; i<=n; i++) if(g[u][i]) { d[i]--; if(!d[i]) s.push(i); } } for(int i=0; i<tmp.size(); i++) if(tmp[i].x!=INF||tmp[i].y!=INF) { int t=min(sum[tmp[i].x],sum[tmp[i].y]); sum[tmp[i].x]=sum[tmp[i].y]=t; } else sum[tmp[i].x]=sum[tmp[i].y]=1; for(int i=1; i<n; i++) { int x=sum[i]-sum[i-1]; printf("%d ",x); } printf("%d\n",sum[n]-sum[n-1]);}int main(){#ifdef debug freopen("in.in","r",stdin);#endif // debug int t; scanf("%d",&t); while(t--) { scanf("%d",&n); scanf("%s",st); make(); solve(); } return 0;}
题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2256
题解:由题目矩阵,可得一系列大小关系(如S[0]-S[1]>0则从0连一条到1的有向边),做拓扑排序,当两数大小相等时,只选一数,最后更改另一数即可。若有数字不受限制则设为1(-10到10任意数)。
0 0
- LA 4255(p309)----Guess
- LA 4255 Guess
- LA 4255 Guess
- LA 4255 Guess 拓扑排序
- uva La 4255 Guess (拓扑排列)
- UvaLive-4255-Guess
- UVALive - 4255 Guess
- UVALive - 4255 Guess
- UVALive 4255 Guess
- UVALive 4255 Guess
- Guess
- guess
- UVALive 4255 Guess【拓扑排序 】
- UVALive 4255-Guess-拓扑排序
- uva 1423 LA 4255
- la la la, la la la
- UValive 4255 Guess(拓扑排序)
- UA 4255 Guess (拓扑排序)
- Java的cmd配置javac能编译成功,但java时出现找不到或无法加载主类 的解决方法
- 从图片中取出像素出现次数最多的颜色(取出图片主色)
- Activity生命周期
- chrome浏览器书签同步问题
- Selenium Chrome启动
- LA 4255(p309)----Guess
- VS2012+EF6+Mysql配置心路历程 - GameMan
- WebAPP输入框被软键盘遮挡肿么办?
- 最大和
- 如何新建gitHub帐号并与自己电脑进行关联
- SSM框架(Spring+SpringMVC+MyBatis)详细整合
- N!末尾有多少个0?
- 5-31 字符串循环左移
- VS2013 EF6连接MySql需要几步?