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 ...
随机推荐
- 10 ajax
Ajax准备知识:json 什么是json? 定义: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w ...
- 1096: [ZJOI2007]仓库建设
1096: [ZJOI2007]仓库建设 思路 斜率优化. 代码 #include<cstdio> #include<iostream> using namespace std ...
- android 事件拦截 (Viewpager不可以左右滑动)
以前没有做过真正的需求,所以从来没有觉得事件拦截分发处理有什么好懂的. 现在做需求了,真的是什么需求都有,你作为开发都要去研究实现.比如说,只能点不能滑动的viewpager.其实这都可以不用view ...
- static任我行- 为人不注意的static
前几天一直在想,static方法如果没有被调用,会不会分配内存的问题,查了一下资料,终于得到了一个官方的说法了. static 方法调用:使用比较频繁的时候使用,像数据库连接串,Connection ...
- 《Cracking the Coding Interview》——第7章:数学和概率论——题目1
2014-03-20 01:57 题目:玩篮球投篮,有两种玩法:要么1投1中,要么3投两中.你单次投篮中的概率是p,那么对于不同的p,哪种玩法胜率更高? 解法:第一种总是胜率更高,可以列不等式算算,结 ...
- .Net导出Word和Excel
using System; using System.Collections.Generic; using System.Linq; using System.Web; public class Ex ...
- .gitignore 中文文件夹无效
有个文件夹名如:测试 在.gitignore中添加 /测试/ 但运行命令git status后发现还是被追踪到了 一番搜索后终于发现.gitignore文件编码是GBK的,重新将文件保存成utf ...
- 自动化测试学习之路--HTML常见元素、属性的简单学习
如何创建html文件: 使用工具:VSCode 1.双击文件名显示区,可快速新建文件. 2.保存文件,文件名.html 3.输入!(必须是英文的!),按 Tab键,可自动生成html格式的文件,如下: ...
- 深入理解CSS中的margin
1.css margin可以改变容器的尺寸 元素尺寸 可视尺寸--标准盒子模型中盒子的宽度是不包括margin值的,clientWidth 占据尺寸--包括margin的宽度 outWidth不在标准 ...
- 轻松精通awk数组企业问题案例
考试题1:处理以下文件内容,将域名取出并根据域名进行计数排序处理:(百度和sohu面试题) oldboy.log http://www.etiantian.org/index.html http:// ...