link

题目大意

给出$m$个不等式关系,问可以从第几个开始确定所有之间的大小关系。若无解请输出是无法确定还是与已知矛盾。

试题分析

这题是真的是坑啊,尽然放在$floyd$传到闭包上面,还用二分,是真的强啊。

其实一下子就会知道其实这是一道拓扑排序的题,所以当我们每次输入问一条边时,我们就去拓扑判断是否会形成环,条件是否充足,与顺序,然后就记得分类讨论即可。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
inline int read(){
int f=,ans=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){ans=ans*+c-'';c=getchar();}
return f*ans;
}
queue<int> que;
int n,m,in[],d[][],find1,k[];
char out[];
char str[];
int topu(){
while(!que.empty()) que.pop();
for(int i=;i<=;i++) k[i]=in[i];
for(int i=;i<=n;i++){if(!in[i]) que.push(i);}
int sx=,num=;
while(!que.empty()){
if(que.size()>) sx=;
int xx=que.front();que.pop();
out[++num]=xx+'A'-;
for(int i=;i<=;i++){
if(d[xx][i]){
k[i]--;
if(k[i]==) que.push(i);
}
}
}
if(num!=n) return ;
if(sx==) return -;
return ;
}
int query,step;
int main(){
// freopen("7.in","r",stdin);
while(){
memset(in,,sizeof(in)),find1=,query=,step=;
memset(d,,sizeof(d));
n=read(),m=read();
if(!n&&!m) return ;
for(int i=;i<=m;i++){
cin>>(str+);
int u=str[]-'A'+,v=str[]-'A'+;
if(str[]=='>') swap(u,v);
if(find1||query) continue;
if(d[v][u]){find1=;printf("Inconsistency found after %d relations.",i);continue;}
if(!d[u][v]){
d[u][v]=;
in[v]++;
}
int pd=topu();
if(pd==){query=;step=i;continue;}
if(pd==){printf("Inconsistency found after %d relations.",i);find1=;continue;}
}
if(query&&find1==){
printf("Sorted sequence determined after %d relations: ",step);
for(int i=;i<=n;i++) cout<<out[i];
printf(".");
}
if(find1==&&query==) printf("Sorted sequence cannot be determined.");
printf("\n");
}
}

[POJ1094] Sorting It All Out的更多相关文章

  1. [poj1094]Sorting It All Out_拓扑排序

    Sorting It All Out poj-1094 题目大意:给出一些字符串之间的大小关系,问能否得到一个唯一的字符串序列,满足权值随下标递增. 注释:最多26个字母,均为大写. 想法:显然,很容 ...

  2. nyoj349 poj1094 Sorting It All Out(拓扑排序)

    nyoj349   http://acm.nyist.net/JudgeOnline/problem.php?pid=349poj1094   http://poj.org/problem?id=10 ...

  3. POJ1094 Sorting It All Out(拓扑排序)

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30110   Accepted: 10 ...

  4. POJ- 1094 Sorting It All Out---拓扑排序是否唯一的判断

    题目链接: https://vjudge.net/problem/POJ-1094 题目大意: 该题题意明确,就是给定一组字母的大小关系判断他们是否能组成唯一的拓扑序列.是典型的拓扑排序,但输出格式上 ...

  5. POJ1094 Sorting It All Out LUOGU 排序

        Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 40012   Accepted ...

  6. poj1094 Sorting It All Out【floyd】【传递闭包】【拓扑序】

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:39731   Accepted: 139 ...

  7. POJ1094 Sorting It All Out —— 拓扑排序

    题目链接:http://poj.org/problem?id=1094 Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Tot ...

  8. POJ1094 Sorting It All Out (floyd传递闭包)

    关系具有传递性,可以用floyd解决. 将关系都看做i<j的形式,令d[i][j]=1,如果d[i][j]=d[j][i]=1,说明矛盾:d[i][j]=d[j][i]=0,说明i与j的关系无法 ...

  9. poj1094 拓扑 Sorting It All Out

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29744   Accepted: 10 ...

随机推荐

  1. 180725-InfluxDB-v1.6.0安装和简单使用小结

    InfluxDB安装和简单使用小结 InfluxDB是一个时序性数据库,因为工作需求,安装后使用测试下是否支持大数据下的业务场景 说明: 安装最新版本 v1.6.0 集群版本要收费,单机版本免费 内部 ...

  2. 那些年安装Appium遇到的坑

      安装appium以及相关的总体记录   1 主要流程是参照这个来 https://www.cnblogs.com/wangyinghao/p/5780151.html 细节参考虫师的博客 http ...

  3. 【坚持】Selenium+Python学习之从读懂代码开始 DAY2

    2018/05/10 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) #No.1 # 二次方程式 ax**2 + bx + ...

  4. Elasticsearch.Net 异常:[match] query doesn't support multiple fields, found [field] and [query]

    用Elasticsearch.Net检索数据,报异常: )); ElasticLowLevelClient client = new ElasticLowLevelClient(settings); ...

  5. win2003系统网络安装——基于linux+pxe+dhcp+tftp+samba+ris

    原文发表于:2010-09-16 转载至cu于:2012-07-21 一.原理简介 PXE(preboot execute environment)工作于Client/Server的网络模式,支持工作 ...

  6. 支持向量机SVM 初识

    虽然已经学习了神经网络和深度学习并在几个项目之中加以运用了,但在斯坦福公开课上听吴恩达老师说他(在当时)更喜欢使用SVM,而很少使用神经网络来解决问题,因此来学习一下SVM的种种. 先解释一些概念吧: ...

  7. New begin

    Purpose 今天更换了id,希望重新沉淀. 晚上看到国外一个博客,落款有个中文: 敬惜字纸. 共勉.

  8. 月薪45K的Python爬虫工程师告诉你爬虫应该怎么学,太详细了!

    想用Python做爬虫,而你却还不会Python的话,那么这些入门基础知识必不可少.很多小伙伴,特别是在学校的学生,接触到爬虫之后就感觉这个好厉害的样子,我要学.但是却完全不知道从何开始,很迷茫,学的 ...

  9. CQOI2018 游记 再见OI,既是反思,也是祝福

    哎,怎么说呢? 时运不齐,命途多舛? 从头开始说吧. 今年的NOIP大家考的都不尽人意,每个人都有或多或少的失误,全部都几十分几十分地丢.最后大家剩下的觉得可能冲击一下省队的人一共只有7个. 伙伴们变 ...

  10. BZOJ 1559 JSOI2009 密码 状压dp+AC自动机+搜索

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1559 分析: 这个题意真的是很**啊!!!直接说每一个字符串至少出现一次不就好了吗... ...