题意 :lucky cat里有翻译。英文也比较好懂。

很容易发现有周期然后就拍就好了

注意每组数据后边都有空行 包括最后一组。一开始以为最后一组没有空行。唉。。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
int t[];//周期
int N,pos[],tmp[];
int k,T,res;
char input[];int ans[];
void dfs(int cur,int depth)
{
if (cur == res) {T = depth; return ;}
dfs(pos[cur],depth + );
}
void calcu()
{
for (int i = ; i <= N; i++)
{
res = i;
dfs(pos[i],);
t[i] = T ;
}
}
int main()
{
//freopen("sample.txt","r",stdin);
bool first = false;
while (scanf("%d",&N)!=EOF)
{
if (N == ) break; for (int i = ; i <= N; i++) scanf("%d",&pos[i]);
calcu();
//for (int i = 1; i <= N; i++) printf("%d ",t[i]);putchar('\n');
while (scanf("%d",&k) != EOF)
{
if (k == ) break;
getchar();
gets(input+);
int len = strlen(input + );
for (int i = len + ; i <= N; i++)
input[i] = ' ';
input[N + ] = '\0';
//for (int i = 1; i <= N; i++) printf("%d ",tmp[i]);puts("");
char output[];
for (int i = ; i <= N; i++) tmp[i] = i;
for (int i = ; i <= N; i++)
{
int tp = k % t[i];
for (int j = ; j < tp; j++)
tmp[i]=pos[tmp[i]];
}
for (int i = ; i <= N;i++) output[tmp[i]] = input[i];
for (int i = ; i <= N;i++)
printf("%c",output[i]);
putchar('\n');
}
putchar('\n');
}
return ;
}

UVA 306 Cipher的更多相关文章

  1. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  2. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  3. Ancient Cipher UVA - 1339

      Ancient Roman empire had a strong government system with various departments, including a secret s ...

  4. uva 1339 Ancient Cipher

    大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:ex ...

  5. 【UVA 1586】Ancient Cipher

    题 题意 给你一个只含CHON的有机物的化学式如C6H5OH求相对分子质量 分析 ... 代码 switch #include<cstdio> #include<cctype> ...

  6. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. 【例题 4-1 UVA - 1339】 Ancient Cipher

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 位置其实都没关系了. 只要每个字母都有对应的字母,它们的数量相同就可以了. 求出每种字母的数量. 排序之后. 肯定是要一一对应的. ...

  8. UVa1399.Ancient Cipher

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

随机推荐

  1. vue 组件轮播联动

    组件轮播联动我使用的是 el-carousel 组件,具体代码如下: <el-carousel trigger="click" :interval="3000&qu ...

  2. python,多线程

    多线程编程,模型复杂,容易发生冲突,必须用锁加以隔离,同时,又要小心死锁的发生. Python解释器由于设计时有GIL全局锁,导致了多线程无法利用多核.多线程的并发在Python中就是一个美丽的梦. ...

  3. 使用泛型类简化ibatis系统架构

    jdk1.5的推出为我们带来了枚举.泛型.foreach循环.同步工具包等等好东西.其中,泛型的使用为我们的代码开发提供了很大的简便,简化了我们的代码. 1.设计思路 1)GenericDao泛型类提 ...

  4. SpringMVC---applicationContext.xml配置详解

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. BZOJ 3027: [Ceoi2004]Sweet

    容斥 #include<cstdio> using namespace std; int a,b,n,m[15]; long long ans=0,mod=2004; long long ...

  6. sprintf()函数使用异常

    调试STM32F103,比如如下代码:使用springf函数,这个函数是把最后两个参数先格式化成字符串 ,输出到ERROR_STRING,如果他们合并的长度大于30会出现深情况? ] sprintf( ...

  7. Linux命令学习总结(一)

    命令 -选项 参数 如果选项是一个单词时,选项前面要加2个- modprobe -r pcspkr   在终端中输入的时候有声音,可以用这个命令屏蔽声音 ,需要root权限 useradd userd ...

  8. 玩转Linux之pwd命令

    玩转Linux之pwd命令 你有没有遇到过需要知道当前所在目录却无从得知?有没有想要复制出当前所在目录层次却不知如何下手?俗话说有困难找警察,想知道目录层次自然要找pwd了.那么问题来了: 什么是pw ...

  9. appium-desktop 环境搭建 Java版

    用的是appium-desktop1.8.1,testng6.11,java-client6.1.0,selenium-java3.13.0 1.下载逍遥模拟器,装好app 2.下载adb,用adb连 ...

  10. [译]14-spring 集合元素的注入

    前面的文章已经介绍了如何往bean里面注入原始类型和引用类型.我们使用bean元素的contructor-arg或property子 元素的value属性注入java原始类型;同理,我们可以使用bea ...