ZOJ 1011 NTA(二叉树+vector)

目标检测中回归损失函数(L1Loss,L2Loss,Smooth L1Loss,IOU,GIOU,DIOU,CIOU,EIOU,αIOU ,SIOU) 为了解决CIoU的问题,有学者在CIOU的基础上将纵横比拆开,提出了EIOU Loss,并且加入Focal聚焦优质的预测框,与CIoU相似的,EIoU是损失函数的解决方案,只用于训练。在错误率小的地方,梯度的值也应当小,反之在错误率大的地方,梯度也应当大,因为这时候我们需要对错误率小的情况进行微调,而错误率大的地方进行大刀阔斧的调整;如下图所示,三种情况IoU都相等,但看得出来他们的重合度是不一样的,左边的图回归的效果最好,右边的最差。DIoU的作者考虑到,在两个框中心点重合时,c与d的值都不变。 阅读详情
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";
    }
  }
}


 

新手必看!一步步教您如何获取可用的D音Cookie(为什么我复制的D音Cookie无法正常使用?) 新手必看!一步步教您如何获取可用的抖音Cookie(为什么我复制的抖音Cookie无法正常使用,无法下载无水印视频?) 阅读详情

相关推荐

Xcelium XRUN实用指南:从入门到高效仿真

本文是Xcelium XRUN仿真工具的实用指南,从基础入门到高效应用全面解析。XRUN作为Cadence Xcelium的统一命令行入口,能自动化编译、精细和仿真流程,大幅提升数字芯片与FPGA验证效率。文章详细介绍了最简命令、波形调试、增量编译、多核并行仿真等核心功能,并提供了管理复杂项目、性能调优与深度调试的进阶技巧,帮助工程师快速上手并精通这一高效仿真工具。

weixin_29238147的博客 751

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神农 760

数字IC后端PPA优化实战:Timing一致性策略与Module Region布局技巧

本文深入探讨了数字IC后端设计中的PPA优化实战,重点解析了Timing一致性问题及其解决方案。通过调整Clock Uncertainty、Timing Derate和RC Scale Factor等关键参数,使Innovus等PR工具的分析结果更接近PrimeTime签核结果。同时,文章详细介绍了Module Region布局技巧,通过为关键模块划定物理区域,优化单元摆放,有效减少线延迟,从而协同提升时序收敛效率与设计可预测性。

weixin_29218963的博客 218

Problem3-1011

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

Ne_Tany的博客 340

给STM32 LWIP做一次‘性能体检’:手把手教你用Wireshark和iperf诊断网络瓶颈

本文详细介绍了如何使用Wireshark和iperf工具对STM32 LWIP网络性能进行全面诊断,帮助开发者精准定位网络瓶颈问题。通过搭建测试环境、集成iperf测试框架、深度报文分析和LWIP配置优化,实现从9KB/s到80MB/s的性能飞跃,特别适用于解决TCP发送速率和卡死问题。

weixin_29631169的博客 301

深入解析uncompyle6反编译pyc文件及常见错误修复指南

本文深入解析了使用uncompyle6工具反编译Python字节码文件(.pyc)的完整流程。针对实践中最高频的KeyError和Python版本范围限制两大错误,提供了详细的修复方案与步骤指南,并分享了处理复杂反编译结果的高级技巧与安全实践,是进行代码恢复、调试与分析的重要参考。

uber9的博客 542

ZOJ 1011 - NTA

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

BIG橙橙滴 755

吃透 AM32 无人机电调:从源码架构到工作原理的全方位解析(附实践指南)(中)

介绍了三相电机控制中的SVPWM算法实现及保护机制设计。SVPWM部分详细解析了电压矢量扇区判断、占空比计算和过调制保护,通过限制占空比范围(0-100%)防止电机失控,并提供了完整的代码实现。保护模块则重点分析了过流、过压/欠压、过温三种保护机制,采用分级处理策略(硬保护停机/软保护降功率)确保系统安全。此外,文章还介绍了参数管理模块在STM32 Flash中的存储方案,包括参数定义、数据结构和读写操作,为电机控制系统提供了完整的解决方案。

bother3000的博客 1397

ZOJ-1011-NTA

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

lengyudota的博客 320

3D数学-动力学

3D数学-11-动力学 旋转运动学 二维旋转动力学 首先我们考虑最简单的情况: 我们将F施加在圆盘(忽略质量)上的一个点(质量为m)上 图中:F为我们施加的力,O是枢轴原点。 通过基本的运算,我们可以得到 F'= F*sinθ 那么切向加速度 a = F'/ m 切向加速度是线性速度的加速度,我们通过除以半径获得角加速度 α = a / r 现在,我们换一种方式,那就是通过杠杆臂的方式去施加力 为了能够计算出m点的角加速度,我们需要引入一个概念:扭矩 他的理解类似于力矩,公式如下 τ = Flsi

韩天衣的博客 2293

Windows环境下如何通过MCP Server实现MySQL安全连接与AI集成?

本文详细介绍了在Windows环境下如何通过MCP Server实现MySQL安全连接与AI集成。MCP Server作为大模型与MySQL之间的安全通道,提供权限控制、SSL加密和协议转换功能,显著提升查询性能。文章包含环境配置、安装指南、安全策略及实战案例,帮助开发者高效实现AI与数据库的安全交互。

hill8的博客 726

浙大ZOJ 1011 NTA问题解决

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

xiaogugood的专栏 2479

科研党必备!用Requests+BeautifulSoup升级版Nature爬虫(含PDF下载功能)

本文介绍了一套基于Python Requests和BeautifulSoup的Nature期刊智能爬虫系统,专为科研人员设计,可自动抓取论文标题、摘要及开放获取的PDF文档。系统采用模块化设计,包含请求管理、PDF检测和邮件通知等功能,确保高效合规地获取学术资源,提升科研效率。

weixin_29041767的博客 267

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的博客 344

VB摄像头监控

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

Statistics and Machine Learning Toolbox

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

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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的博客 265

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

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

ZOJ 1011 NTA

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

Crux.D的专栏 2891

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

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的专栏 1560

zoj 1944 Tree Recovery (二叉树)

Tree Recovery Time Limit: 2 Seconds      Memory Limit: 65536 KB Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with

Just do it ! 1849
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址