这一道题的话  数据有一点问题    ........     例如 不过 还是   能理解一下  试试吧  .........

A<B
B<C
C<A
A<C
B<A
这几组数据 明显反映出来 这是成环的 , 然后 按照 输入输出案例来说 这个是 有序的 ABC

 

题目要求     在每组数据的   第一行  给你需要排序 的 字母数    和  他们之间的关系数量      然后  输入每组数据    你首先许亚萍判断在输入  第几组 数据的时候 出现了 环     其次判断    到第几组关系的时候   可以确定唯一的序列  如果上面两个 都不行的话    就输出   第三种情况  不能确定  唯一 的   排序序列

内存越界.....醉了 . 明天看  睡觉觉

 #include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<cctype>
using namespace std;
int n,m,a[][],visited[],flag,fuck,mark,result[],temp[],count1,flag1;
void topsort(int q)
{
fuck=;
for(int j=;j<n;j++)
temp[j]=visited[j]; //
count1=;
for(int i=;i<=n;i++) // 其实只是普通的 拓扑排序 重复化了一下而已 ...
{
fuck=mark=;
for(int j=;j<n;j++)
{
if(temp[j]==)
{
flag=j;
mark++;
}
}
if(mark==)
{
printf("Inconsistency found after %d relations.\n",q+);
flag1=fuck=;
break;
}
temp[flag]--; // 找到了 flag 他没有儿子 / 现在 将他标记为 -1;
if(mark==)
{
result[i]=flag; // 将 该点储存起来
count1++;
}
for(int j=;j<n;j++) // 将 flag的 所有爸爸的 儿子数 -1
{
if(a[flag][j])
{
temp[j]--;
}
}
}
}
int main()
{
while(scanf("%d%d",&n,&m),(n||m))
{
flag1=fuck=count1=mark=flag=;
memset(visited,,sizeof(visited));
memset(a,,sizeof(a));
for(int i=;i<m;i++)
{
char d,c,b;
scanf(" %c%c%c",&b,&d,&c);
if(flag1)
continue;
a[b-'A'][c-'A']=; // c 有一个叫做b 的儿子
visited[c-'A']++; // c 的 儿子 数量 ++
topsort(i); // 第一次进去的时候 就相当于 只有一组的关系
if(fuck)
;
else
{
if(count1==n)
{
printf("Sorted sequence determined after %d relations: ",i+);
for(int i=;i<=n;i++)
printf("%c",result[i]+'A');
printf(".\n");
flag1=;
}
}
if(!flag1&&i==m-)
{
printf("Sorted sequence cannot be determined.\n");
flag1=;
}
}
}
return ;
}
 #include<stdio.h>
#include<string.h>
int map[][],indegree[],q[];
int TopoSort(int n) //拓扑排序
{
int c=,temp[],loc,m,flag=,i,j; ////flag=1:有序 flag=-1:不确定
for(i=;i<=n;i++)
temp[i]=indegree[i];
for(i=;i<=n;i++)
{
m=;
for(j=;j<=n;j++)
if(temp[j]==) { m++; loc=j; } //查找入度为零的顶点个数
if(m==) return ; //有环
if(m>) flag=-; // 无序
q[c++]=loc; //入度为零的点入队
temp[loc]=-;
for(j=;j<=n;j++)
if(map[loc][j]==) temp[j]--;
}
return flag;
} int main()
{
int m,n,i,sign; //当sign=1时,已得出结果
char str[];
while(scanf("%d%d",&n,&m))
{
if(m==&&n==) break;
memset(map,,sizeof(map));
memset(indegree,,sizeof(indegree));
sign=;
for(i=;i<=m;i++)
{
scanf("%s",str);
if(sign) continue; //一旦得出结果,对后续的输入不做处理
int x=str[]-'A'+;
int y=str[]-'A'+;
map[x][y]=;
indegree[y]++;
int s=TopoSort(n);
if(s==) //有环
{
printf("Inconsistency found after %d relations.\n",i);
sign=;
}
if(s==) //有序
{
printf("Sorted sequence determined after %d relations: ",i);
for(int j=;j<n;j++)
printf("%c",q[j]+'A'-);
printf(".\n");
sign=;
}
}
if(!sign) //不确定
printf("Sorted sequence cannot be determined.\n");
}
return ;
}

Sorting It All Out 拓扑排序+确定点的更多相关文章

  1. ACM: poj 1094 Sorting It All Out - 拓扑排序

    poj 1094 Sorting It All Out Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & ...

  2. poj 1094 Sorting It All Out (拓扑排序)

    http://poj.org/problem?id=1094 Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

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

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

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

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

  5. POJ 1094:Sorting It All Out拓扑排序之我在这里挖了一个大大的坑

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

  6. [ACM_模拟] POJ 1094 Sorting It All Out (拓扑排序+Floyd算法 判断关系是否矛盾或统一)

    Description An ascending sorted sequence of distinct values is one in which some form of a less-than ...

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

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

  8. POJ 1094 Sorting It All Out (拓扑排序) - from lanshui_Yang

    Description An ascending sorted sequence of distinct values is one in which some form of a less-than ...

  9. poj 1094 Sorting It All Out_拓扑排序

    题意:是否唯一确定顺序,根据情况输出 #include <iostream> #include<cstdio> #include<cstring> #include ...

随机推荐

  1. nginx代理标准配置

    #nginx开启的进程数worker_processes   4;     #4核CPU   #定义全局错误日志定义类型,[debug|info|notice|warn|crit]error_log  ...

  2. python实现给定一个数和数组,求数组中两数之和为给定的数

    给定一个整数数组和一个目标值,找出数组中和为目标值的两个数.你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target = ...

  3. Linux:SAMBA共享、NFS共享、Autofs自动挂载

    SAMBA.NFS共享区别 NFS开源文件共享程序:NFS(NetworkFile System)是一个能够将多台Linux的远程主机数据挂载到本地目录的服务,属于轻量级的文件共享服务,不支持Linu ...

  4. jet flow in a combustion chamber

    Table of Contents 1. contacts 2. Paper digest 2.1. LES vs. RANS 2.2. Dynamics of Transient Fuel Inje ...

  5. SQL学习笔记:表的约束

    目录 NOT NULL约束 INDEX 索引 CHECK 约束 DEFAULT 约束 UNIQUE 约束 PRIMARY KEY 约束 FOREIGN KEY 约束:简单的说,就是创建表的时候,对表或 ...

  6. Spring security 5 Authorize Configuration

    1. Spring Security 核心请求,认证配置类 WebSecurityConfigurerAdapter protected void configure(HttpSecurity htt ...

  7. 【01】CSS制作的图形

    [01]CSS制作的图形   绘制五角星:   通过border绘制三角形.然后通过transfrom来旋转35度. 绘制对称的图形,最后绘制顶部的三角形即可.   元素本身,加上:before和:a ...

  8. 53. spring boot系列合集【从零开始学Spring Boot】

    前40章节的spring boot系列已经打包成PDF在csdn进行发布了,如果有需要的可以进行下载. 下载地址:http://download.csdn.net/detail/linxinglian ...

  9. C#装饰模式

    using System;using System.Collections.Generic;using System.Text; namespace 装饰模式{    class Person    ...

  10. hdu 1533KM算法

    #include<stdio.h> #include<string.h> #include<math.h> #define inf 0x3fffffff #defi ...