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. 美国末日AI System设计分享

    引言 好久没有写博客了,这半年在游戏公司工作,过得比较充实,每天不是add feature就是debug,所以忽视了写博客.今天发一篇关于AI博客. 主要是最近看了一些关于"The Last ...

  2. Python常用模块之PIL

    官方网址:http://www.pythonware.com/products/pil/index.htm Python Imaging Library (PIL) Python图像库(PIL)将图像 ...

  3. how to update product listing price sale price and sale date using mobile App

    Greetings from Amazon Seller Support, Thank you for writing back to us. I have reviewed our previous ...

  4. 第四次ScrumMeeting博客

    第四次ScrumMeeting博客 本次会议于10月28日(六)22时整在3公寓725房间召开,持续15分钟. 与会人员:刘畅.辛德泰.窦鑫泽.张安澜.赵奕. 1. 每个人的工作(有Issue的内容和 ...

  5. python循环结构

    while循环 while 条件表达式: 语句块 while语句的条件表达式是循环条件,常用的是关系表达式或者逻辑表达式,语句块是循环执行的语句. n=1 p=1 num=int(input(&quo ...

  6. ES6的新特性(18)——async 函数

    async 函数 含义 ES2017 标准引入了 async 函数,使得异步操作变得更加方便. async 函数是什么?一句话,它就是 Generator 函数的语法糖. 前文有一个 Generato ...

  7. ncnblogs.com的用户体验

    你是什么样的用户, 有什么样的心理, 对cnblogs 的期望值是什么? 我是一名普通的学生,上cnblogs的期望是发表博客完成老师布置的任务. 当你第一次使用cnblogs 的功能的时候, 碰到了 ...

  8. 超级迷宫需求分析与建议-NABCD模型

    超级迷宫需求分析与建议-NABCD模型 制作者-姜中希 1N-Need 需求  首先这是一个手机游戏风靡的时代,随着智能手机不断的更新问世,4G网络的不断扩大普及,越来越多的手机游戏受到广大玩家的追捧 ...

  9. UEditor前端配置项说明

    UEditor 的配置项分为两类:前端配置项 和 后端配置项 后端配置项具体看这个文档L:后端配置项说明 本文档介绍如何通过设置前端配置项,定制编辑器的特性,配置方法主要通过修改ueditor.con ...

  10. C#获取当前路径的方法如下

    1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName -获取模块的完整路径. 2. System.Environm ...