POJ 1094 Sorting It All Out【拓扑序
来源:互联网 发布:设有数组定义,x 编辑:程序博客网 时间:2024/05/22 08:21
嗯……大过年的先说声新年快乐啦【估计没人看就写给以后可能会复习的我好了【【
呃……我这道题也是WA的哭了出来 直接从腊月WA到了今年……呃……初三了?
重点是,这道题秉承了样例必须水的……呃……优良传统x 于是各种被水淹没 不知所措
终于 挂在了这个数据上
4 4
A<B
C<B
D<B
B<A
首先这的确是一道水题………然而为什么会WA的这么凄惨…………在对比了我的程序和题解之后【终于 终于找到一个小细节 我发现现在条件不充分的时候就直接return了……然而A的那个程序却继续找了下去【这个就血崩了x
嗯……重点就是,先判环,,我也是这么觉得的【前面两个逗号并不是逼死强迫症233我也并不话唠啦x 】 然而,万万没想到啊,就这么忘了,条件不充分也可能有环啊…………于是,在发现条件不充分的时候,还要继续topo判环……反正 有环的优先级比找不到的优先级更高所以咯……【哭着上代码【其实在debug的时候重新码了一遍,长得应该和某位菊苣的题解十分相似【根本就是一样吧……orzorz
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int n,m,sign;bool ways[26][26];int indu[26];char tmp[10];int now[26];int q[30],head,tail;int Topo(){head=tail=0;int flag=1;for(int _=0;_<n;++_)now[_]=indu[_];int cnt,loc;for(int ff=1;ff<=n;++ff){cnt=0;for(int _=0;_<n;++_)if(!now[_])++cnt,loc=_;if(!cnt)return0;if(cnt>1)flag=-1;<span style="white-space:pre"></span>//这里就是重点啊啊啊……我当时直接return -1 了……然而WA了好久都不知道怎么挂的……☆☆☆now[loc]=-1,q[tail++]=loc;for(int _=0;_<n;++_)if(ways[loc][_])--now[_];}return flag;}int main(){freopen("233.in","r",stdin);while(scanf("%d%d",&n,&m)&&(n||m)){memset(ways,0,sizeof(ways));memset(indu,0,sizeof(indu));sign=0;for(int i=1;i<=m;++i){scanf("%s",tmp);if(sign)continue;ways[tmp[0]-'A'][tmp[2]-'A']=1;++indu[tmp[2]-'A'];int s=Topo(); if(s==0) { printf("Inconsistency found after %d relations.\n",i); sign=1; } if(s==1) { printf("Sorted sequence determined after %d relations: ",i); for(int j=0;j<n;j++) printf("%c",q[j]+'A'); printf(".\n"); sign=1; }}if(!sign)printf("Sorted sequence cannot be determined.\n");}return 0;}
0 0
- POJ 1094 Sorting It All Out【拓扑序
- POJ 1094 Sorting It All Out(拓扑排序)
- Poj 1094-Sorting It All Out [拓扑排序]
- POJ 1094-Sorting It All Out 拓扑排序
- zoj 1060 || poj 1094 Sorting It All Out(拓扑排序)
- POJ 1094 Sorting It All Out 拓扑排序
- POJ 1094 Sorting It All Out 拓扑排序
- POJ 1094 Sorting It All Out 拓扑排序
- poj 1094 Sorting It All Out 拓扑排序
- POJ 1094 Sorting It All Out (拓扑排序)
- POJ 1094 Sorting It All Out 拓扑排序
- poj 1094 Sorting It All Out(拓扑排序)
- poj 1094 Sorting It All Out 拓扑排序
- poj 1094 Sorting It All Out 拓扑排序
- poj 1094 Sorting It All Out (拓扑排序)
- poj 1094 Sorting It All Out (拓扑排序)
- Poj 1094 Sorting It All Out——拓扑排序
- POJ 1094 Sorting It All Out 拓扑排序+Floyd算法
- java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
- 第22讲-控制结构与流程图-练习
- 【HDU2825】Wireless Password【AC自动机】【状压DP】
- 1106. Lowest Price in Supply Chain (25)
- 阿里云
- POJ 1094 Sorting It All Out【拓扑序
- LeetCode刷题 (Python) | 328. Odd Even Linked List
- Unity Update 详解
- #学习笔记#(38)js轮播图
- 《笨办法学Python》 第37课手记
- Android开发学习之路--UI之简单聊天界面
- [LeetCode]53. Maximum Subarray
- 1001. A+B Format (20)
- 1002. A+B for Polynomials (25)