SPOJ LEONARDO Leonardo Notebook

2023-11-07 20:19
文章标签 notebook spoj leonardo

本文主要是介绍SPOJ LEONARDO Leonardo Notebook,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Description

— I just bought Leonardo’s secret notebook! Rare object collector Stan
Ucker was really agitated but his friend, special investigator Sarah
Keptic was unimpressed. — How do you know it is genuine? — Oh, it must
be, at that price. And it is written in the da Vinci code. Sarah
browsed a few of the pages. It was obvious to her that the code was a
substitution cipher, where each letter of the alphabet had been
substituted by another letter. — Leonardo would have written the
plain-text and left it to his assistant to encrypt, she said. And he
must have supplied the substitution alphabet to be used. If we are
lucky, we can find it on the back cover! She turned up the last page
and, lo and behold, there was a single line of all 26 letters of the
alphabet:

QWERTYUIOPASDFGHJKLZXCVBNM 

— This may be Leonardo’s instructions meaning that each A in the
plain-text was to be replaced by Q, each B with W, etcetera. Let us
see… To their disappointment, they soon saw that this could not be
the substitution that was used in the book. Suddenly, Stan brightened.
— Maybe Leonardo really wrote the substitution alphabet on the last
page, and by mistake his assistant coded that line as he had coded the
rest of the book. So the line we have here is the result of applying
some permutation TWICE to the ordinary alphabet! Sarah took out her
laptop computer and coded fiercely for a few minutes. Then she turned
to Stan with a sympathetic expression. — No, that couldn’t be it. I am
afraid that you have been duped again, my friend. In all probability,
the book is a fake. Write a program that takes a permutation of the
English alphabet as input and decides if it may be the result of
performing some permutation twice. Input

The input begins with a positive number on a line of its own telling
the number of test cases (at most 500). Then for each test case there
is one line containing a permutation of the 26 capital letters of the
English alphabet. Output

For each test case, output one line containing Yes if the given
permutation can result from applying some permutation twice on the
original alphabet string ABC…XYZ, otherwise output No.

找规律可以发现,如果循环 A 的长度n为奇数,那么 A2 还是一个长度为 n 的循环,如果是偶数,A2就是两个长度为 n2 的循环的乘积。
所以长度为奇数的循环可以单独出现,但是长度为偶数的循环一定是成对出现的。只需要统计 B <script type="math/tex" id="MathJax-Element-360">B</script>中偶数长度的循环的个数,任意长度的循环必须恰好有偶数个。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int n=26;
char s[30];
int cnt[30],vis[30];
bool solve()
{int i,p,now;scanf("%s",s+1);memset(vis,0,sizeof(vis));memset(cnt,0,sizeof(cnt));for (i=1;i<=n;i++)if (!vis[i]){p=s[i]-'A'+1;vis[p]=1;now=1;while (p!=i){p=s[p]-'A'+1;vis[p]=1;now++;}cnt[now]++;}for (i=2;i<=n;i+=2)if (cnt[i]&1) return 0;return 1;
}
int main()
{int T;scanf("%d",&T);while (T--)if (solve()) printf("Yes\n");else printf("No\n");
}

这篇关于SPOJ LEONARDO Leonardo Notebook的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/366041

相关文章

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

【Jupyter Notebook】汉化

1.打开:Anaconda Prompt 2.输入:"activate Zhui01"(注意:Zhui01是刚创建的环境名字) activate Zhui01 3.输入:"pip install jupyterlab-language-pack-zh-CN" pip install jupyterlab-language-pack-zh-CN 4.打开:Jupyter Noteb

[轻笔记] jupyter notebook 指定conda虚拟环境

安装插件 conda install nb_conda 进入conda env conda activate ${env_name}conda install ipykernelconda deactivate #3. 运行jupyter notebook conda activate # 需要先进入conda环境,非常重要jupyter notebook 会发现,在ju

jupyter notebook - python23 并存使用

在终端输入 $python2 -m pip install ipykernel$python2 -m ipykernel install --user$python3 -m pip install ipykernel$python3 -m ipykernel install --user ---------------------- Kernels for Python 2 and 3

【Jupyter】 Notebook 中的 IPython 魔法:12个必知实用技巧

Jupyter Notebook 作为一个强大的交互式计算环境,结合 IPython 的功能,为数据科学家和程序员提供了丰富的工具。本文将介绍12个在 Jupyter Notebook 中使用 IPython 的实用技巧 1. 清除输出:使用 clear_output() from IPython.display import clear_output# 执行一些操作print("This

【SPOJ】1825 Free tour II 点分治

传送门:【SPOJ】1825 Free tour II 题目分析:敲了两遍。。。 本题是论文题,具体见漆子超论文《分治算法在树的路径问题中的应用》。 在以root为根的第 i 棵子树上,我们用G[ i ,j ]表示root的第 i 棵子树的路径上严格有 j 个黑点的路径的最长长度。用F[ i ,j ]表示在root为根的第 i 棵子树的路径上不超过 j 个黑点的路径的最长长度。因

【SPOJ】Triple Sums【FFT】

传送门:【SPOJ】Triple Sums 题目分析: 首先我们不考虑 i<j<k i<j<k这个条件,构造多项式: Y=∑xai \qquad\qquad\qquad Y = \sum x^{a_i} 那么 ai+aj+ak=S ai+aj+ak=S的个数即 xai+aj+ak=S x^{a_i+a_j+a_k=S}的个数,等价于 Y3中xS Y^3中x^S的系数。 然后我们考虑容斥

【Anaconda】修改jupyter notebook默认打开的工作目录、jupyter notebook快捷键

jupyter notebook快捷键 针对单元格的颜色蓝色命令行模式绿色编辑模式两种模式的切换编辑模式切换到命令行模式 >>> esc键命令行模式切换到编辑模式 >>> 鼠标左键或者直接按enter键1.标题的书写方式1:1.esc进入命令行模式2.按m键3.写内容4.运行单元格即可方式2:1.编辑模式下直接写文本内容2.按esc键进入命令行模式3.再按数字键选择几级标题4.运行单元格即可

[转载]如何向IPython Notebook中导入.py文件

相关文章链接 如何向IPython Notebook中导入.py文件 如何将 ipynb 发布到 blog 中(html, markdown格式) Introducing IPython Notebook Beginner’s IPython Notebook Tutorial Example notebook showing how to do statistics

[转载]jupyter notebook中创建tensorflow的kernel

我在conda下创建了tensorflow的env,然而在jupyter notebook中却无法选择此kernel,历经google多方搜索,解决方法如下。 首先在conda下激活env activate tensorflowenv 然后安装ipykernel pip install ipykernel 最后将此kernel链接到jupyter notebook中 pyt