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 ...
随机推荐
- Android自定义组件之简单组合
Android自定义控件有两种,一种是组合.比如一个linearlayout 里面有textview,imageview. 这样的好处是,写一个就可以多处使用. view_image_and_butt ...
- 利用split方法计算字符串中出现字母最多的次数
最近练习一些简单的算法题,知道自己很不聪明,但却没想到用了这么久,划算不划算是个需要考虑的问题, 其中有个算法是:统计一个字符串出现最多的字母,网上很多自己的见解,但是才疏学浅,有些地方看的有点困难, ...
- libmt.so: undefined reference to `av_find_stream_info@LIBAVFORMAT_53'
[root@localhost instance]# make gcc -O3 -g -I/usr/include/ -I/usr/include/glib- -fexceptions -fstack ...
- ScrollView中ViewPager无法正常滑动问题
本文主要介绍如何解决ViewPager在ScrollView中滑动经常失效.无法正常滑动问题. 解决方法只需要在接近水平滚动时ScrollView不处理事件而交由其子View(即这里的ViewPage ...
- 《Cracking the Coding Interview》——第17章:普通题——题目8
2014-04-28 23:35 题目:最大子数组和问题. 解法:O(n)解法. 代码: // 17.8 Find the consecutive subarray with maximum sum ...
- 【NOIP 2017 提高组】列队
题目 有一个 \(n\times m\) 的方阵,每次出来一个人后向左看齐,向前看齐,询问每次出来的人的编号. \(n\le 3\times 10^5\) 分析 我们考虑离队本质上只有两种操作: 删除 ...
- FTP2
FTP: 环境:windows, python 3.5功能:1.用户加密认证,可自行配置家目录磁盘大小2.多用户登陆3.查看当前目录(家目录权限下)4.切换目录(家目录权限下)5.上传下载,进度条展示 ...
- hadoop-搭建(转)--亲测好用 (一)
1)JDK软件 下载地址:http://www.oracle.com/technetwork/java/javase/index.html 2)Hadoop软件 下载地址:http://hadoop. ...
- Spring Cloud Config 搭建Config 服务
配置中心: open API 配置生效监控 一致性的K-V存储 统一配置的实时推送 配置全局恢复.备份.历史版本 高可用集群 通过config 获取配置,流程: 下面介绍,基于spring cloud ...
- C# 命名管道
有些场合需要高效率,进行线程间通信,可以使用 C#命名管道.