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 ...
随机推荐
- spark提交运算原理
前面几天元旦过high了,博客也停了一两天,哈哈,今天我们重新开始,今天我们介绍的是spark的原理 首先先说一个小贴士: spark中,对于var count = 0,如果想使count自增,我们不 ...
- Python文章推荐1
Table of Contents 1. 分享最近看到的python相关的几篇好文(我只是想偷懒) 1.1. 形象解释了什么是GIL 1.2. 知乎上 Pythonic 相关 1.3. evil &q ...
- is 和 == 的区别,utf和gbk的转换,join用法
is 和 == 的区别 # is 比较的是内存地址 # == 比较的是值 a = 'alex' b = 'alex' #int,str(小数据池)会被缓存,为了节约内存 print(id(a),id( ...
- 3226: [Sdoi2008]校门外的区间
链接 思路 bug漫天飞... 维护一颗线段树,支持区间赋值,和区间异或.因为会处理到一些方括号还是圆括号的问题,所以对于每一个下标都乘2,假设中间有一个.5即可,都变成了方括号,输出在处理一下. U ...
- Javacript实现倒计时
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- Java 泛型 二
一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: 1 public class GenericTest { 2 3 public static void main(Stri ...
- win32 signal
Remarks The signal function enables a process to choose one of several ways to handle an interrupt ...
- 《Cracking the Coding Interview》——第18章:难题——题目5
2014-04-29 01:51 题目:你有一个文本文件,每行一个单词.给定两个单词,请找出这两个单词在文件中出现的其中一对位置,使得这两个位置的距离最短. 解法:我的思路是建立倒排索引,计算出所有单 ...
- 23、php知识点总结基础教程--part-1
1.基本语法 PHP 脚本可放置于文档中的任何位置. PHP 脚本以 <?php 开头,以 ?> 结尾 <?php // 此处是 PHP 代码 ?> PHP 文件的默认文件扩展 ...
- ASP.NET Core [3]:进入HttpContext的世界(笔记)
原文链接:http://www.cnblogs.com/RainingNight/p/httpcontext-in-asp-net-core.html HttpContext是ASP.NET中的核心对 ...