UVA 306 Cipher
题意 :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的更多相关文章
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- Ancient Cipher UVA - 1339
Ancient Roman empire had a strong government system with various departments, including a secret s ...
- uva 1339 Ancient Cipher
大意:读入两个字符串(都是大写字母),字符串中字母的顺序可以随便排列.现在希望有一种字母到字母的一一映射,从而使得一个字符串可以转换成另一个字符串(字母可以随便排列)有,输出YES:否,输出NO:ex ...
- 【UVA 1586】Ancient Cipher
题 题意 给你一个只含CHON的有机物的化学式如C6H5OH求相对分子质量 分析 ... 代码 switch #include<cstdio> #include<cctype> ...
- UVa LA 3213 - Ancient Cipher 水题 难度: 0
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【例题 4-1 UVA - 1339】 Ancient Cipher
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 位置其实都没关系了. 只要每个字母都有对应的字母,它们的数量相同就可以了. 求出每种字母的数量. 排序之后. 肯定是要一一对应的. ...
- UVa1399.Ancient Cipher
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
随机推荐
- 霍夫直线检测 opencv
本次实验是检测图像中的直线,用到了HoughLines()和HoughLinesP()函数,其中HoughLinesP()称为累计概率霍夫变换,实验结果显示累计概率霍夫变换要比标准霍夫变换的效果好.具 ...
- impala presto SparkSql性能测试对比
目标是为测试impala presto SparkSql谁的性能更佳,以下结果底层查询的都是普通textfile snappy压缩后数据,规模为15台机器,若以orcfile.parquet速度能 ...
- 我教你怎么玩转git
我教你怎么玩转git 1.想要练习解决冲突? 很好办.创建本地分支,a,b, a上面,这样改.b上面那样改. 然后你就解决冲突就可以了. 可以merge 或者cheerypick 2.想要玩一个不要历 ...
- 【Python】python模块加载
一个python文件就是一个模块 标准模块 python自带的模块就是标准模块,也就说可以直接import进来的就是标准模块 import datetime import random 第三方模块 别 ...
- python基础实践(二)
-*-越简单越快乐-*-# -*- coding:utf-8 -*-# Author:sweeping-monkQuestion_1 = "python中的整数运算"Method_ ...
- 01、dos命令行的常用命令
cd 进入指定目录cd.. 返回上一级目录cd\ 退回盘符根目录dir 列出当前目录下的文件以及文件夹md 创建目录rd 删除目录del 删除文件cls ...
- LINQ to Entities 不识别方法“System int string 转换的问题
这个问题困扰了挺久,网上找了挺多方法 都太好使. 分几种情况. 1.如果查询结果 转换,那比较容易. var q = from c in db.Customers where c.Country == ...
- spring security注解(1)
Chapter 15. 基于表达式的权限控制 Spring Security 3.0介绍了使用Spring EL表达式的能力,作为一种验证机制 添加简单的配置属性的使用和访问决策投票,就像以前一样. ...
- 【bzoj1976】[BeiJing2010组队]能量魔方 Cube 网络流最小割
题目描述 一个n*n*n的立方体,每个位置为0或1.有些位置已经确定,还有一些需要待填入.问最后可以得到的 相邻且填入的数不同的点对 的数目最大. 输入 第一行包含一个数N,表示魔方的大小. 接下来 ...
- [AT2698] Don't Be a Subsequence
题目大意:给定一个字符串,求一个最短的串要求没有在该字符串的子串中出现过,如果有多个,输出字典序最小的那一个. 题解:倒着跑一遍原字符串(以下编号为$1\sim n$),按出现了所有$26$个字母来分 ...