题目描述

As a punishment for misbehaving, Byteasar is to calculate a certain mysterious and nasty Boolean-valued function , which is defined for a pair of positive integer sequences , as follows:

boolean if then return else if then return else return .

Where: denotes the set of members of the sequence (order and repetitions of elements are insignificant), denotes the longest prefix (initial part of any length) of the sequence , such that , denotes the longest suffix (final part of any length) of the sequence , such that , denotes the logical conjunction, - true, - false, and - cardinality of set .

For example, for the sequence we have:

For very large data a programme calculating values of the function directly from definition is too slow by any standards.

Therefore you are to make these calculations as fast as possible.

Write a programme that reads several pairs of sequences from the standard input and prints out the values on the standard output for every input pair

你的任务是计算一个函数F(x, y),其中x和y是两个正整数序列。F的定义如下:

boolean F(x, y)
if W(x) ≠ W(y) then return 0
else if |W(x)| = |W(y)| = 1 then return 1
else return F(p(x), p(y)) AND F(s(x), s(y)).
W(x)表示序列x中元素的集合。(元素的顺序和出现次数将被无视)
p(x)表示序列x的最长前缀,满足:W(x) ≠ W(p(x))
s(x)表示序列x的最长后缀。满足:W(x) ≠ W(s(x))
|Z|表示集合Z中元素个数

The first line of the standard input contains one integer () denoting the number of sequence pairs to analyse.

Next line hold descriptions of test cases.

The first line of each description contains two integers and () separated by a single space and denoting the lengths of the first and second sequence, respectively.

The second line holds integers () that form the sequence , separated by single spaces.

The third line holds integers (), that form the sequence , separated by single spaces.

输出格式

The output should consist of exactly lines; the -th line (for ) should contain a single integer - 0 or 1 - the value of for -th test case.

输入样例:                                                              输出样例:

2                                                                               0
4 5                                                                            1
3 1 2 1
1 3 1 2 1
7 7
1 1 2 1 2 1 3
1 1 2 1 3 1 3

翻译:

作为对行为不端的惩罚,Byteasar将计算一个神秘而讨厌的布尔值函数,该函数是为一对正整数序列定义的,如下所示:

布尔if-then返回else if-then返回else-return。

其中:表示序列的成员集(元素的顺序和重复不重要),表示序列的最长前缀(任何长度的起始部分),表示序列的最长后缀(任何长度的最后部分),表示逻辑连接,-true,-false,和-集的基数。

例如,对于序列,我们有:

对于非常大的数据,直接从定义计算函数值的程序按任何标准都太慢。

因此,您必须尽可能快地进行这些计算。

编写一个程序,从标准输入读取多对序列,并打印出每个输入对的标准输出值

标准输入的第一行包含一个整数(),表示要分析的序列对的数量。

下一行保存测试用例的描述。

每个描述的第一行包含两个整数和(),由单个空格分隔,分别表示第一个和第二个序列的长度。

第二行包含构成序列的整数(),由单个空格分隔。

第三行保存整数(),它们构成序列,由单个空格分隔。

输出应完全由行组成;第-行(for)应该包含一个整数-0或1-第-个测试用例的值。

题解网址:https://www.luogu.com.cn/problem/solution/P3481

洛谷 P3481 [POI2009]PRZ-Algorithm Speedup相关推荐

  1. 洛谷P5911 [POI2004]PRZ

    Description 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 桥已经很旧了, 所以它不能承受太重的东西. 任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍 ...

  2. 图论--网络流--最大流 洛谷P4722(hlpp)

    题目描述 给定 nn 个点,mm 条有向边,给定每条边的容量,求从点 ss 到点 tt 的最大流. 输入格式 第一行包含四个正整数nn.mm.ss.tt,用空格分隔,分别表示点的个数.有向边的个数.源 ...

  3. 洛谷-题解 P2672 【推销员】

    独门思路!链表加优先队列! 这题一望,贪心是跑不掉了,但是我贪心并不好,所以想到了一个复杂一些但思路更保稳的做法 思路: 1 因为是离线操作,所以我们可以倒着求,先求x=n的情况,因为那样直接就知道了 ...

  4. 洛谷 P1387 最大正方形

    P1387 最大正方形 题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=10 ...

  5. 洛谷P2763 试题库问题

    题目:https://www.luogu.org/problemnew/show/P2763 题目描述 «问题描述: 假设一个试题库中有n道试题.每道试题都标明了所属类别.同一道题可能有多个类别属性. ...

  6. 动态规划——洛谷_P1057传球游戏

    题目: 题目描述 上体育课的时候,小蛮的老师经常带着同学们一起做游戏.这次,老师带着同学们一起做传球游戏.游戏规则是这样的:n个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球, ...

  7. 洛谷专题训练 ——【算法1-1】模拟与高精度

    洛谷题单[算法1-1]模拟与高精度 ACM-ICPC在线模板 题单链接: [算法1-1]模拟与高精度 下面的这一坨都是洛谷题单上的东东 题单简介 恭喜大家完成了第一部分语言入门,相信大家已经可以使用 ...

  8. 洛谷P1006 传纸条 (棋盘dp)

    好气,在洛谷上交就过了,在caioj上交就只有40分 之前在51nod做过这道题了. https://blog.csdn.net/qq_34416123/article/details/8180902 ...

  9. 洛谷P2904 [USACO08MAR]跨河River Crossing 动态规划

    洛谷P2904 [USACO08MAR]跨河River Crossing 动态规划 区间DP f[ i ] 表示 将 i 头牛 运了过去,然后John 又返回所需要的最少时间 1 #include & ...

最新文章

  1. python 聚类_使用python+sklearn实现聚类性能评估中随机分配对聚类度量值的影响
  2. RedHat Enterprise Linux Server 5 安装序列号
  3. JPA入门简介与搭建HelloWorld(附代码下载)
  4. java 匹配最后一次出现的字符_在Java中查找字符串中字符的最后一次出现
  5. List集合中对象的排序
  6. apue.h文件找不到的解决办法
  7. msys2 预编译的包 查询和下载
  8. OSI七层网络协议归纳
  9. js按钮触发网页提醒_js实现按钮点击事件 在页面上点击函数,查看执行效果
  10. androidmmi可以卸载吗_删除Android自带的系统软件注意事项
  11. 极客时间马哥教育-云原生训练营第一周作业-20221016
  12. [SSL_CHX][2021-8-18]取余
  13. MySQL权限篇之SHOW DATABASES及SHOW VIEW
  14. Core Text 实践:自定义每个字的位置
  15. BZOJ2716天使玩偶
  16. 2021鹅厂产品管培生宣讲会干货总结
  17. springboot中使用注解获取前台header信息
  18. python 最准确的图片转文字软件,图片转文字软件哪个好?5款好用的图片转文字软件推荐...
  19. 完成知乎项目的登录和注册功能(二)
  20. docker替换阿里云镜像源

热门文章

  1. snntorch:P2—【LIF神经元模型】手撕公式、代码实现与演示
  2. CISP-PTE选择题整理(一)
  3. 如何利用游戏模拟真实世界?游戏和游戏引擎的可能性|无学科专栏
  4. 微信各类地图语音导航
  5. Windows开机缓慢解决方法
  6. [除草]BZOJ 2548 灭鼠计划
  7. vue制作腾讯地图组件
  8. 英语学习app开发笔记
  9. 色彩的世界之色彩心理
  10. 微信小程序 | 10.wx.request( )发送请求