ZOJ 1011 NTA(二叉树+vector)

常见的AXI总线仲裁器概述-AXI协议理解(一) SoC 设计广泛采用共享总线式的片上通信,其中的仲裁器是共享总线的关键技术之一。AMBA AXI 总线协议以高性能、高频率的系统设计为目标,适合高带宽、低延迟的系统设计,可以达到高频率的操作而不需要复杂的总线桥,满足众多部件的接口要求,具备高度灵活的互联结构,并且向后兼容 AHB 和 APB 接口。 阅读详情
NTA

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The NTA (Non-deterministic Tree Automata) is a kind of tree structure device. The device is built in a set of operating rules. With these rules the device can produce several signals, which will form a signal system. In such a system, one signal is the starting signal, several signals are the acceptable signals, and the others are the auxiliary ones. A pair of signals is said to be an acceptable pair if both two signals of the pair are acceptable.

The trees discussed here are all binary trees. Every non-leaf node has two successors. In any finite tree, each node has a signal-transmitting element. When a signal arrives at one node, the signal meets the signal transmitting substance, and triggers off signal reactions, which will produce several pairs of signals. Then the device selects a pair of signals non-deterministically and sends them to its successors. The first signal in the signal pair is sent to the left successive node and the second one is sent to the right successive node.

The whole operation for an NTA is as follows:

The device first sends the starting signal to the root node. According to the signal transmitting substance at the root node, the device selects a pair of signals non-deterministically and sends the first to the left son and the second to the right son. Each of the two signals then meets the signal transmitting substance at the corresponding node and produces another two signals. The course proceeds down until the signals arrive at the leaves.

If a signal reaches one leaf and the leaf can produce a pair of acceptable signals, we say the leaf is "shakable". A transmission of signals from the root to leaves is said to be valid if all leaves are "shakable". A tree structure with signal transmitting substance is valid if there exists such a valid transmission. A tree is invalid if all the transmissions are invalid.

For simplicity, we denote the signal transmitting elements by consecutive lowercase letters "a", "b", "c", etc.. The signals of an NTA are consecutive numbers 0,1,2, ..., and so on. The first signal 0 is always a starting signal. Thus the signals for a 4-signal NTA are "0" "1" "2" and "3". Accepting signals are arranged at the end of the number sequence so that if a 4-signal NTA has two accepting signals, the accepting signals are "2" and "3". The transition rules of signals are based on a transition table. For example, the following table describes a transition table with four signals "0", "1", "2", "3" and with three signal transmitting elements "a", "b" and "c".

Tabc
0(1,2)(2,1)(1,0)
1(2,2)(0,2),(1,0)(3,2)
2(2,2)(2,3)(1,2)
3(1,2)(2,1)(3,2)

In this transition table some reactions of signals on certain signal transmitting elements are deterministic, and others are non-deterministic. In the example above, if signal "1" reaches the node with the transmitting element "b", the reaction is non-deterministic.

Now your task is to write a program to judge if a tree structure with certain signal transmitting substance is valid.


Input

The input file contains several cases. Each case describes a sequence of NTA descriptions and some initial tree configurations. The first line for each case consists of three integers n, m and k. The integer n is the number of signals, m indicates the number of accepting signals, and k is number of signal transmitting elements. The following n k lines describe the transition table in row-major order. Each transition of a signal on signal transmitting element is given on a separate line. On such line every two numbers represent a possible transition.

This is followed by the description of tree structures. For every tree structure a number L is given on a separate line to indicate the level of the tree. The following L+1 lines containing a sequence of letters describe the tree structure. Each level is described in one line. There exist one space between two successive letters. The 0-th level begins firstly. In the tree structure, the empty nodes are marked by "*". The tree structure with L=-1 terminates the configurations of tree structures for that NTA, and this structure should not be judged.

The input is terminated by a description starting with n=0, m=0 and k=0. This description should not be processed.

Note: In each case, NTA will have at most l5 signals and 10 characters. The level of each tree will be no more than 10.


Output


For each NTA description, print the number of the NTA (NTAl, NTA2, etc.) followed by a colon. Then for each initial tree configuration of the NTA print the word "Valid" or "Invalid".

Print a blank line between NTA cases.


Sample Input

4 2 3
1 2
2 1
1 0
2 2
0 2 1 0
3 2
2 2
2 3
1 2
1 2
2 1
3 2
3
a
b c
a b c b
b a b a c a * *
2
b
a b
b c * *
-1
0 0 0


Output for the Sample Input

NTA1:
Valid
Invalid

思路:将信号读入,用个二维table【】【】vector存储,后面的二叉树字符是满二叉树所以用个字符数组存储二叉树。

    然后模拟信号发射,依次遍历信号,发现合法就返回真就行。

失误点:两个case间需要加空行,PE了两次。

 

#include<iostream>
#include<vector>
using namespace std;
const int mm=20;
class signal
{public:
  int lchild,rchild;
};
char tree[123456];
int n,m,k,h;
int tree_deep;
vector<signal>table[mm][mm];
void read_data()
{ 
  char ch;
  for(int i=0;i<n;i++)
  for(int j=0;j<k;j++)
  {
    table[i][j].clear();
    while(1)
    {
      signal ss;cin>>ss.lchild>>ss.rchild;
      table[i][j].push_back(ss);
      ch=cin.get();
      if(ch=='\n')break;
    }
  }
}
void read_tree()
{ char ch;
  tree_deep=0;///从0开始存
  for(int i=0;i<=h;i++)
  for(int j=0;j<(1<<i);j++)
  {
    cin>>ch;tree[tree_deep++]=ch;
  }
}
bool judge(int sig,int node)
{
  int sig1,sig2;
  if(tree[node]=='*'||node>=tree_deep)///若达到了叶子节点
  { ///判断信号合法
    if(sig<n-m)return false;
    else return true;
  }
  int k=tree[node]-'a';
  int left=node*2+1;///因为从0开始所有每次都得加1;
  int right=left+1;
  for(int i=0;i<table[sig][k].size();i++)
  {
    sig1=table[sig][k][i].lchild;
    sig2=table[sig][k][i].rchild;
    if(judge(sig1,left)&&judge(sig2,right))return true;
  }
  return false;
}
int main()
{ int cas=0;
  while(cin>>n>>m>>k)
  { if(n==0&&m==0&&k==0)break;
    read_data();
    if(cas&&n)
    cout<<"\n";
    cout<<"NTA"<<++cas<<":\n";
    while(cin>>h)
    {if(h==-1)break;
      read_tree();
     if(judge(0,0))cout<<"Valid\n";
     else cout<<"Invalid\n";
    }
  }
}


 

vue3 web项目引入高拍仪 高拍仪的引入步骤就两步,安装SDK,然后根据官网的api进行开发。根据自己需要的功能,请求对应的接口。 阅读详情

相关推荐

NVIDIA Tao Toolkit环境配置踩坑

请搭配食用该文章为 Tao 安装中可能出现的问题进行解答,如果存在本文章中没出现的问题,欢迎提问,由我复现后更新文章。由于大部分云服务器厂商不能支持 docker,因此我使用的环境为2023年5月27日在平台租的 3080 旧版环境进行实验。

qq_36630208的博客 771

ZOJ1011 NAT

NTA Time Limit: 2 Seconds      Memory Limit: 65536 KB The NTA (Non-deterministic Tree Automata) is a kind of tree structure device. The device is built in a set of operating rules. With the

coder神农 759

高效获取Sentinel-2影像:哥白尼数据中心下载全流程解析

本文提供了一份从哥白尼数据中心高效下载Sentinel-2卫星影像的保姆级指南。详细解析了从账号注册、使用Copernicus Browser界面、精准划定研究区域,到利用云量覆盖、时间范围等关键条件筛选L2A地表反射率产品的全流程,旨在帮助用户快速获取高质量遥感数据,避免常见错误。

weixin_29247219的博客 256

Problem3-1011

简单题意: 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。 解题思路: 首先先代入几个数进行运算,通过简单归纳总结出一定的规律,即a[i] = a[i-1] + a[i+1], 然后就按照惯有的套路进行计算即可,最重要的是找到匹配的公式。 代码如下: #include using namespa

Ne_Tany的博客 340

大模型训练显存瘦身全记录:从ZeRO-3参数分区到CPU Offload的硬件协奏曲

本文详细解析了如何通过ZeRO-3参数分区与CPU/NVMe卸载技术优化大模型训练的显存使用。结合bf16混合精度与梯度累积等策略,实现在消费级GPU上高效训练百亿参数模型,显著提升硬件利用率与训练效率。

weixin_29051245的博客 435

基于C#的软PLC梯形图编辑器开发实战

本文详细介绍了基于C#开发软PLC梯形图编辑器的实战过程。文章从核心数据结构设计入手,阐述了如何利用C#的面向对象特性构建梯形图元素模型,并实现了图形编辑、指令表输入、逻辑连接拓扑重建等关键功能。重点剖析了模拟PLC执行引擎的扫描周期与能流传递算法,让梯形图逻辑在PC上“活”起来。最后探讨了定时器指令实现、性能优化及项目集成等进阶内容,为工业自动化软件集成提供了灵活高效的解决方案。

weixin_28314575的博客 404

ZOJ 1011 - NTA

ZOJ 1011 - NTA 英文题目 《算法分析与设计-以大学生程序设计竞赛为例》

BIG橙橙滴 755

C#上位机与MES系统数据对接:从协议选型到安全传输的实战解析

本文详细解析了C#上位机与MES系统数据对接的全过程,从协议选型到安全传输的实战技巧。针对工业互联网场景下的数据对接挑战,提供了RESTful API、MQTT和OPC UA等协议的选型建议,并分享了健壮性设计、异常处理和安全传输的实用代码示例,帮助开发者高效实现数据上传与系统集成。

weixin_30566063的博客 105

ZOJ-1011-NTA

从根结点开始是信号0,信号发射单元是a,查表该结点产生信号(1,2),信号1给左,信号2给右,标注在结点的连线上,左子树的发射单元是b,可以产生两种信号:(0,2),(1,0)。程序会将这两种信号都向下遍历一遍,最后取信号(1,0)。重复该过程至所有结点。最后我们看到,所有叶子结点产生的信号,都是合法信号,即都是信号2和3,因此该树是有效的,输出单词 valid。 从样例看出,该表不是一个普通的二...

lengyudota的博客 320

YOLO详解

本文参考知乎 https://zhuanlan.zhihu.com/p/25236464 1. YOLO的创新点 YOLO将物体检测作为回归问题求解。基于一个单独的end-to-end网络,完成从原始图像的输入到物体位置和类别的输出。 从网络设计上,YOLO与two steps的目标检测方法如RCNN、Fast RCNN和Faster RCNN的区别如下: YOLO训练和检测均是在一个单独网...

UnknownPlayer的博客 9948

【PCB专题】Allegro导出3D文件

Allegro中如何导出3D文件,有没有一键导出操作?

一点硬件 4987

浙大ZOJ 1011 NTA问题解决

一、工程代码及算法设计注释 --------------------------------------------------nta.h---------------------------------------------- #ifndef JLU_CCST_NTA_H #define JLU_CCST_NTA_H #include struct SignalPair{ in

xiaogugood的专栏 2479

sap中途启用物料账

spro->控制->产品成本控制->实际成本核算/物料分类帐->实际成本核算->激活实际成本的在产品。spro->控制->产品成本控制->实际成本核算/物料分类帐->实际成本核算->激活实际成本组件划分。spro->控制->产品成本控制->实际成本核算/物料分类帐->实际成本核算->激活实际成本核算。spro->控制->产品成本控制->实际成本核算/物料分类帐->激活评估范围的物料分类账。2.对于之前存在物料移动,但是期初没有库存的物料,物料分类账里追踪不到相关物料信息。1.需要激活物料分类账。

Yeol827的博客 992

zoj 1011

// C++Exercise.cpp : 定义控制台应用程序的入口点。 // #include #include #include #include #include #include #include #include #include using namespace std; int n, m, k, L; int index; typedef struct{ int lsig;

zju2016的博客 341

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

zoj 1011 NTA

ZOJ Problem Set - 1011 NTA Time Limit: 2 Seconds      Memory Limit: 65536 KB The NTA (Non-deterministic Tree Automata) is a kind of tree structure device. The device is built in a set of operating

u011922039的专栏 815

VB摄像头监控

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

ZOJ-1011 NTA

ZOJ-1011 NTA Question Description: NTA Time Limit: 2000 msMemory Limit: 65536 KB The NTA (Non-deterministic Tree Automata) is a kind of tree structure device. The device is built in a set of operating rules. With these rules the device can produce several

ShallowDreamJY的博客 264

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

zoj 1011 NTA

数据读入可真让我想了好半天,酝酿好久才敢开写,又一次证明小心总是没错的。 过了样例后,一直WA,奇怪了好久,看了网上的代码才想起,我忘了清vector了,吃一堑长一智吧。。。。。 #include #include #include #include #define MAX 151 using namespace std; typedef struct node{     int

journey_fan的专栏 939

ACM-FZOJ1011解题报告

新浪博客 发表时间 -- 2009-07-28 21:19:38 Power Strings    这道题题目意思很明显,要让我们求最长重复字符串,刚好,老师讲了KMP算法,想想也应该是用KMP算法来解决,但也找不到好的解决办法...    上网查了下,发现了别人的一个思想,就是题目要找最长重复字符串,我们先用字符串长度减去找到的位置,然后用字符串长度来判断是否能整除于它,行的话

兔子临死前的专栏 779

ZOJ1011

#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;memory.h&gt; #include &lt;string.h&gt; int n, m, k, lev;//树的层数 int transition[155][155];//存放表格中数据 char tree[11][2222]; int dfs...

名场聚散多高富,沧海浮沉一屌丝 559

ZOJ 1011 NTA

 题目不难,但非常恶心,输入需要字符串处理,分明就是考察当年学生的打字速度……我打了一个多钟头,还从scanf换成了cin,真失败。写递归搜索的时候有些没有信心,结果居然一次AC。听起来就像是“直觉告诉我,真相只有一个!”做了一些小处理,比如全置*,然后空节点判断,这样就避免了考虑叶子。 #include iostream>#include string>using names

Crux.D的专栏 2887

ZOJ1011-NTA

#include<iostream> #include<vector> using namespace std; struct signal { int left,right; }; vector<signal> table[20][20]; int n,m,k; int treeLevel; char tree[1000]; int ...

zjutsunny的博客 260

zoj 1011NTA

//#include #include #define MAXN 15 #define MAXK 10#define MAXL 10using namespace std;int m, n, k;struct mypair{ int a, b; mypair *next;

yllfever的专栏 1557
上一篇: USACO section 3.3 Riding the Fences(欧拉通路的遍历,dfs)
下一篇: USACO section 3.3 Shopping Offers(DP或最短路)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值