poj 1206
/**
题意: 给定一序列,置换k次之后 输出其状态
置换: 考察循环节长度,
思路: 分别求出每个元素的循环节的大小,用k 模其大小,大的k次之后的位置, 输出即可
**/ #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; int main()
{
int n;
int sec[];
int path[][];
int len[];
while(cin>>n&&n){
memset(path,,sizeof(path));
memset(len,,sizeof(len));
int t;
for(int i=;i<n;i++){
cin>>t;
sec[i] = t-;
}
for(int i=;i<n;i++){
int j= i;
path[i][] = j;
len[i] = ;
for(j=sec[j];j!=i;j=sec[j])
path[i][len[i]++] = j;
}
int k;
char str[];
while(cin>>k&&k){
getchar();
gets(str);
char res[];
//int len = strlen(str);
int m=;
for(;str[m];m++);
for(int j=m;j<n;j++)
str[j]=' ';
for(int i=;i<n;i++)
res[path[i][k%len[i]]] = str[i];
res[n]='\0';
cout<<res<<endl;
}
cout<<endl;
}
return ;
}
poj 1206的更多相关文章
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 51nod 1206:Picture 求覆盖周长
1206 Picture 题目来源: IOI 1998 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 给出平面上的N个矩形(矩形的边平行于X轴和 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- SSRS(rdl报表)分页显示表头和冻结表头
<TablixRowHierarchy> <TablixMembers> <TablixMember> ...
- ER图与UML图
ER图:实体-联系图(Entity-Relation Diagram)用来建立数据模型,在数据库系统概论中属于概念设计阶段,ER图提供了表示实体(即数据对象).属性和联系的方法,用来描述现实世界的概念 ...
- Android判断网络连接状态
有的时候我们的应用可能需要判断当前设备是否联网 private void init() { /** 获得系统级联网管理员对象 */ ConnectivityManager manager = (Con ...
- GCD 续集
1.延迟执行 1.1.perform... // 3秒后自动回到当前线程调用 self 的 download: 方法,并且传递参数:@“http://xxx.jpg” [self performSel ...
- iOS根据2个经纬度计算距离
#pragma mark - calculate distance 根据2个经纬度计算距离 #define PI 3.14159265358979323 +(double) CalculationDi ...
- C语言处理CSV文件的方法(一)
什么是CSV文件 CSV是 Comma-separated values (逗号分隔值)的首字母缩写,它通常是以逗号且不仅限于逗号分隔各个值,我们都叫他CSV. 看下面的例子: China, Shan ...
- Cross-site scripting
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web appli ...
- row_number() over (partition by....order by...)用法 分组排序
row_number() over (partition by....order by...)用法 分组排序 row_number() OVER (PARTITION BY COL1 ORDER BY ...
- 如何使Label带有链接??此法感觉有点取巧!!!
关键代码 /**************************************************************第一行***************************** ...
- c语言中 %p的含义
格式控制符“%p”中的p是pointer(指针)的缩写.指针的值是语言实现(编译程序)相关的,但几乎所有实现中,指针的值都是一个表示地址空间中某个存储器单元的整数.printf函数族中对于%p一般以十 ...