ZOJ 1060 poj 1094 Sorting It All Out(拓扑排序或 弗洛德)

全局最小割 一个无向连通网络,去掉一个边集可以使其变成两个连通分量则这个边集就是割集;最小割集当然就权和最小的割集。 可以用最小切割最大流定理: 1.min=MAXINT,确定一个源点 2.枚举汇点 3.计算最大流,并确定当前源汇的最小割集,若比min小更新min 4.转到2直到枚举完毕 5.min即为所求输出min     不难看出复杂度很高:枚举汇点要O(n),最 阅读详情

Sorting It All Out

Time Limit: 2 Seconds Memory Limit: 65536 KB

An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C, D implies that A < B, B < C and C < D. in this problem, we will give you a set of relations of the form A < B and ask you to determine whether a sorted order has been specified or not.

Input

Input consists of multiple problem instances. Each instance starts with a line containing two positive integers n and m. the first value indicated the number of objects to sort, where 2 <= n <= 26. The objects to be sorted will be the first n characters of the uppercase alphabet. The second value m indicates the number of relations of the form A < B which will be given in this problem instance. Next will be m lines, each containing one such relation consisting of three characters: an uppercase letter, the character "<" and a second uppercase letter. No letter will be outside the range of the first n letters of the alphabet. Values of n = m = 0 indicate end of input.

Output

For each problem instance, output consists of one line. This line should be one of the following three:

Sorted sequence determined after xxx relations: yyy...y.
Sorted sequence cannot be determined.
Inconsistency found after xxx relations.

where xxx is the number of relations processed at the time either a sorted sequence is determined or an inconsistency is found, whichever comes first, and yyy...y is the sorted, ascending sequence.

Sample Input

4 6
A<B
A<C
B<C
C<D
B<D
A<B
3 2
A<B
B<A
26 1
A<Z
0 0

Sample Output

Sorted sequence determined after 4 relations: ABCD.
Inconsistency found after 2 relations.
Sorted sequence cannot be determined.


Source: East Central North America 2001
Submit Status


思路:拓扑排序,判断是否出现环,或者能排出序列,当出现多于一个入度为0的点则为不确定。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
using namespace std;
const int mm=1100;
char out[mm];
bool vis[77];
vector<int >mp[77];
int cu[mm],cun[mm],n,m,pos;
bool yes;
int topsort()
{ for(int i=0;i<30;i++)
  cu[i]=cun[i];
  int top=-1,ttnum=0;
  for(int i=0;i<n;i++)
    if(cu[i]==0)
    cu[i]=top,top=i;
    if(cu[top]!=-1)yes=1;///只要入度为0的点多于1个那么就是不确定序列,但人需要判断是否有环
  for(int i=0;i<n;i++)
  {
    if(top==-1)return 0;
    else
    {
      int num=top;top=cu[top];
      pos+=sprintf(out+pos,"%c",char('A'+num));
      for(int j=0;j<mp[num].size();j++)
        if(--cu[mp[num][j]]==0)
        cu[mp[num][j]]=top,top=mp[num][j];
        if(top>=0&&cu[top]!=-1)yes=1;
    }
  }return 1;
}
int main()
{
  while(cin>>n>>m)
  { if(n==0&&m==0)break;
   char sss,u,v;
   memset(cun,0,sizeof(cun));
   memset(mp,0,sizeof(mp));
   memset(vis,0,sizeof(vis));
   int ans=0,z=0,pp=0;
    for(int i=0;i<m;i++)
    {
      cin>>u>>sss>>v;
      cun[v-'A']++;mp[u-'A'].push_back(v-'A');
      if(!vis[v-'A'])vis[v-'A']=1,pp++;
      if(!vis[u-'A'])vis[u-'A']=1,pp++;///判断不同的字符数是否刚好为n个
      if(ans==0)
      {pos=0;yes=0;///yes是真说明拓扑排序的序列仍是不确定,但需要看看是否有环,无环则continue;
       if(topsort()){if(yes)continue;if(pp==n)ans=1,z=i+1;}
       else ans=-1,z=i+1;
      }
    }
    if(ans==1)cout<<"Sorted sequence determined after "<<z<<" relations: "<<out<<".\n";
    else if(ans==-1)cout<<"Inconsistency found after "<<z<<" relations.\n";
    else cout<<"Sorted sequence cannot be determined.\n";

  }
}




CrewAI 多 Agent 实战包 v1(Mock免Key跑通+通义千问可选+流水线样例) 本资源是 CrewAI 风格多 Agent 可运行工程包:研究→写作→审校等流水线样例。无 API Key 时自动降级 Mock 引擎跑通;有 DASHSCOPE_API_KEY 时可接真实 CrewAI + 通义千问。含中文 README、samples、smoke 留档、单元测试。本包不含密钥。关联博客:https://blog.youkuaiyun.com/mtl1994 立即下载

相关推荐

市场销售总监年终汇报必备PPT.pptx

市场销售总监年终汇报必备PPT

uva 10917 Walk Through the Forest(最短路+DP路径,4级)

Description Problem C: A Walk Through the Forest Jimmy experiences a lot of stress at work these days, especially since his accident made working difficult. To relax after a hard day, he lik

nealgavin的专栏 2130

半桥LLC谐振变换器开环+闭环仿真设计资料(Simulink仿真实现)

内容概要:本文档系统性地介绍了半桥LLC谐振变换器的开环与闭环仿真设计方法,基于Simulink平台构建完整的仿真模型,涵盖系统建模、关键参数设计、控制策略实现及动态性能验证全过程。重点阐述了LLC谐振变换器的工作原理、谐振腔参数(Lr、Cr、Lm)的优化设计方法、零电压开关(ZVS)与零电流开关(ZCS)等软开关技术的实现机制,并深入探讨电压/电流双闭环控制策略,特别是恒压恒流双竞争控制逻辑的切换机制与稳定性保障。资料配套提供完整的仿真模型、详细说明文档及参考文献,有助于全面掌握其在启停过程、负载突变等工况下的动态响应特性与系统鲁棒性调控方法。; 适合人群:具备电力电子技术基础理论知识和Simulink仿真操作能力的高校研究生、科研机构研究人员,以及从事高频高效开关电源、新能源汽车车载充电机(OBC)、充电桩电源、数据中心供电等领域的工程技术人员。; 使用场景及目标:① 掌握LLC谐振变换器在实际工程中的精确建模与仿真分析流程;② 深入理解并独立实现从开环频率调制到闭环反馈控制的平滑切换逻辑;③ 应用于高效率DC-DC变换器、电动汽车充电系统、可再生能源并网电源等场景下的控制系统设计与性能优化; 阅读建议:建议结合所提供的仿真模型进行分步调试与参数扫描实验,重点关注控制器带宽设计、谐振元件参数匹配对效率的影响以及系统上电过程中的软启动策略设计,同时推荐对比学习全桥LLC、CLLC等衍生拓扑的相关资料,以建立完整的谐振变换器控制体系认知。

CF-29C - Mail Stamps(DFS+离散化)

C - Mail Stamps Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 29C Description

nealgavin的专栏 1707

SOP 配电网故障重构方法研究【IEEE33节点】(Matlab代码实现)

内容概要:本文围绕基于SOP(Soft Open Point)的配电网故障重构方法展开研究,采用IEEE33节点标准配电系统作为仿真测试平台,利用Matlab进行代码实现与仿真验证。研究重点在于通过SOP这一柔性电力电子装置实现故障后网络拓扑的快速重构,提升供电恢复能力与系统可靠性。文中详细阐述了故障重构的数学建模过程,结合优化算法实现负荷转供与孤岛划分的协同决策,在保证辐射状运行约束的前提下,最大限度恢复失电负荷,并降低网络损耗。该方法充分体现了SOP在主动配电网中的灵活调控优势,为现代智能配电网的自愈控制提供了有效技术路径。; 适合人群:电气工程及相关专业的高校研究生、从事配电网自动化与智能电网研究的科研人员,以及具备一定Matlab编程基础和电力系统分析背景的研发技术人员。; 使用场景及目标:① 掌握基于SOP的配电网故障恢复机制与重构策略设计;② 学习如何在Matlab环境下构建IEEE33节点系统模型并实现故障重构算法;③ 深入理解含分布式电源与柔性装置的主动配电网优化运行方法; 阅读建议:建议结合电力系统分析基础知识,重点关注SOP的建模方式、故障重构的优化目标与约束条件设定,并动手实践Matlab代码以加深对算法流程和仿真结果的理解。

安检机图像处理避坑指南:从条纹校正到物质分类,那些论文里没写的工程细节

本文深入探讨了双能X射线安检机图像处理中的关键工程实践,从条纹校正到物质分类,揭示了论文中未提及的实用技巧。针对探测器校正、物质分类模糊、伪彩色系统设计等核心问题,提供了动态参数更新、空间上下文分析和自适应色彩映射等解决方案,助力提升安检系统的准确性和鲁棒性。

weixin_30325487的博客 887

hdu 4756 Install Air Conditioning(MST+全边次小树,4级)

Install Air Conditioning Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 174    Accepted Submission(s): 23 Problem Description   

nealgavin的专栏 1443

UR机械臂正逆运动学解析:从DH参数到8组解的完整求解策略

本文深入解析UR机械臂的正逆运动学求解策略,从DH参数原理到完整的8组解求解方法。详细介绍了正运动学的坐标变换过程,以及逆运动学中Atan2函数和三角恒等变换的应用,并揭示了8组解的产生机制。通过实际案例和调试技巧,帮助工程师掌握UR机械臂运动学求解的核心技术。

weixin_29094775的博客 413

hdu 4650 Minimum Average Weight Path(最短路,5级)

第4场多校联合训练解题报告——详见杭电ACM微博~ Minimum Average Weight Path Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 94    Accepted Submissio

nealgavin的专栏 1389

python docx设置标题中文字体rPr.rFonts.set(qn(‘w:eastAsia‘),u‘黑体‘),报错‘NoneType‘ object has no attribute ‘set‘

一、我的代码: 因为要编一个报告自动化生成的代码,所以用了python docx,在设置标题自己写了一段代码,要求将标题设置成:一级标题 黑体 小四 from docx import Document from docx.oxml.ns import qn from docx.shared import Pt def add_Head(document, level, text, font, size): # document word对象 # level 几级标题 # text 标题内容 # f

qq_40272386的博客 8853

从零实现高精度手势检测:OpenCV+MediaPipe模型移植实战(2)(附c++完整代码)

上篇已经介绍了手掌检测的方法。本章将在手掌检测的基础上,完成手指关节的检测。

qq_37160641的博客 2665

UVA1416 Warfare And Logistics(LA4080)(最短路,5级)

Description The army of United Nations launched a new wave of air strikes on terrorist forces. The objective of the mission is to reduce enemy's logistical mobility. Each air strike will destro

nealgavin的专栏 1342

终端运行脚本报: 因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fw link/?LinkID=135170 中的 about_Execution_

PowerShell 执行策略是一种安全机制,用于控制哪些脚本可以在系统上运行。默认情况下,Windows 系统会设置较为严格的执行策略,以防止恶意脚本的执行。执行策略有以下几种常见级别:Restricted(限制):不允许运行任何脚本。AllSigned(全部签名):仅允许运行经过数字签名的脚本。RemoteSigned(远程签名):允许运行本地脚本,但远程下载的脚本需要数字签名。Unrestricted(无限制):允许运行所有脚本,但会警告未签名的脚本。

欢迎来到我的技术博客!这里是一个专注于软件开发的地方,我将分享关于 Java、Python、C++ 和易语言等多种编程语言的教程、技巧、最佳实践以及开发经验。 5080

HDU 1068 Girls and Boys(二分图最大独立点集,3级)

Girls and Boys Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status   Appoint description:  System Crawler  (2012-10-30) Description the secon

nealgavin的专栏 1229

【YOLOv12改进trick】高效多尺度卷积注意力EMCAD_Block模块引入YOLOv12,实现涨点和效率提升,含创新点Python代码

EMCAD引入YOLOv12模块,实现高效多尺度注意力模块引入到YOLOv12中的快速涨点及效率提升

向上生长的程序媛的博客 851

设计四翼无人机(Quadcopter)的自主降落控制算法

为四翼无人机建立动力学模型,包括其姿态(Pitch, Roll, Yaw)和位置(X, Y, Z)的变化。可以使用Aerospace Blockset中的预制模块,或者根据具体需求构建自定义模型。示例:简化动力学模型利用块模拟四翼无人机的基本行为,确保模型能够反映电机输出如何影响姿态和位置变化。

amy_mhd的博客 242

uva 1364 - Knights of the Round Table(点双连通分量,5级)

Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising tha

nealgavin的专栏 1224

【YOLOv10改进[Backbone]】使用ADNet改进YOLOv10在噪声干扰下的目标检测效果(图像去噪)+ 含全部代码和详细修改方式 + 手撕结构图 + 全网首发

使用ADNet改进YOLOv10在噪声干扰下的目标检测效果(图像去噪)+ 含全部代码和详细修改方式 + 手撕结构图 + 全网首发 + 遥遥领先

静谧、淡雅 2857

ZOJ 3780 Paint the Grid Again(topsort)

ZOJ Problem Set - 3780 Paint the Grid Again Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N × N cells. He wants to paint each cell with a specific color (either black

nealgavin的专栏 1209

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

10054 - The Necklace(欧拉回路+DFS,2级)

Problem D: The Necklace  My little sister had a beautiful necklace made of colorful beads. Two successive beads in the necklace shared a common color at their meeting point. The figure belo

nealgavin的专栏 1184

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

hdu 4725 The Shortest Path in Nya Graph(堆+dij,最短路,5级)

The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 193    Accepted Submission(s): 38 Problem Description Th

nealgavin的专栏 1167

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

hdu 4685 Prince and Princess(最大匹配+强连通所点,5级)

Prince and Princess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 248    Accepted Submission(s): 76 Problem Description There are n p

nealgavin的专栏 1149

uva 11374 Airport Express(最短路dijistra+堆优化,4级)

Description Problem D: Airport Express In a small city called Iokh, a train service, Airport-Express, takes residents to the airport more quickly than other transports. The

nealgavin的专栏 1124

uva 1423 - Guess (topsort,4级)

Given a sequence of integers, a1, a2,..., an , we define its sign matrix S such that, for 1ijn , Sij = `` + " if ai +...+ aj > 0 ; Sij = `` - " if ai +...+ aj  ; and Sij = ``0" otherwise. For exa

nealgavin的专栏 1121

hdu 4679 Terrorist’s destroy (DP or 树直径,4级)

Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 132    Accepted Submission(s): 20 Problem Description There is a ci

nealgavin的专栏 1068
上一篇: ZOJ 2913 Bus Pass(BFS+滚动队列)
下一篇: CF-30 D - King's Problem?(枚举+最短路)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值