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. php常用的几个预定义变量

    __FILE__:返回所在路径文件名和文件名称 __DIR__:返回文件所在的完整目录 __LINE__:返回当前文件代码的行号 __CLASS__:返回当前类名 __FUNCTION__:返回当前方 ...

  2. Appium 运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported for (转)

    现象:Appium运行脚本报错InvalidSelectorException: Message: Locator Strategy 'css selector' is not supported f ...

  3. 【java请求】- jmeter_jdbc脚本实战

    一,导入 使用Jmeter运行Java脚本,需要用到Jmeter的提供的框架jar包(分别在jmeter目录下的lib和ext目录下)1.ApacheJMeter_core.jar2.ApacheJM ...

  4. Oracle集合

    --union 并集 select * from emp where ename like '%A%' union select * from emp where ename like '%M%'; ...

  5. Smokeping配置

    参考文档: 官网:http://oss.oetiker.ch/smokeping/ 参考:http://jaminzhang.github.io/monitoring/smokeping-deploy ...

  6. php异步学习(2)

    PHP开启异步多线程执行脚本   场景要求 客户端调用服务器a.php接口,需要执行一个长达5s-20s不等的耗资源操作,但是客户端响应请求时间为5秒(微信公众账号服务器请求响应超时时间),5s以上无 ...

  7. Cube Stacking P0J 1988(加权并查集)

    Description Farmer John and Betsy are playing a game with N (1 <= N <= 30,000)identical cubes ...

  8. JS 操作 checkbox(cc角色管理等)

    1.获取选中的权限的个数 var size=$("input[name='privileges']:checked").size();

  9. OpenFlow协议

    功能 1.0版本Openflow:控制器通过Openflow协议与交换机建立了安全通道(Sceure Channel),下发流表. 1.3版本Openflow:多控制器,多流表. 用于实现Contro ...

  10. .net学习-扩展

    uwp uwpapp-斗鱼,微信等 云和移动优先 远程桌面连接设置 teamviewer V8内核 Node.js javascript 事件循环 express框架 bootstrap NoSQL ...