HDU 2371
知道了怎么置换之后,就可以用矩阵来置换了,但这道题一直关于置换的地方读不明白。
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; const int Maxn=100;
int pn[Maxn],xn[Maxn],bn[Maxn];
int ansp[Maxn];
char str[Maxn];
struct Matrax {
int m[Maxn][Maxn];
};
int n,m;
Matrax per,a; void initial(){
memset(per.m,0,sizeof(per.m));
for(int i=0;i<n;i++){
per.m[i][i]=1;
}
memset(a.m,0,sizeof(a.m));
for(int i=0;i<n;i++)
a.m[pn[i]][i]=1;
} Matrax multi(Matrax ae,Matrax b){
Matrax c;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c.m[i][j]=0;
for(int k=0;k<n;k++){
c.m[i][j]+=ae.m[i][k]*b.m[k][j];
}
}
}
return c;
} Matrax quick(int k){
Matrax ans=per;
Matrax p=a;
while(k){
if(k&1){
ans=multi(ans,p);
}
k=k>>1;
p=multi(p,p);
}
return ans;
} int main(){
while(scanf("%d%d",&n,&m)!=EOF){
if(n==0&&m==0) break;
for(int i=0;i<n;i++){
scanf("%d",&bn[i]);
bn[i]--;
xn[i]=i;
}
for(int i=0;i<n;i++) //为什么要加这个,我想不明白,只好跟着别人加了
pn[bn[i]]=i;
getchar();
gets(str);
initial();
Matrax ans=quick(m);
for(int i=0;i<n;i++){
ansp[i]=0;
for(int k=0;k<n;k++)
ansp[i]+=xn[k]*ans.m[k][i];
}
for(int i=0;i<n;i++)
cout<<str[ansp[i]];
cout<<endl;
}
return 0;
}
HDU 2371的更多相关文章
- 矩阵十题【五】 VOJ1049 HDU 2371 Decode the Strings
题目链接:https://vijos.org/p/1049 题目大意:顺次给出m个置换,重复使用这m个置换对初始序列进行操作.问k次置换后的序列.m<=10, k<2^31. 首先将这m个 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- python:sql建表语句转换为json
第一种sql格式: CREATE TABLE prpcitem_car ( proposalno ) NOT NULL, itemno ,) NOT NULL, riskcode ) NOT NULL ...
- oc1
// zs.h #ifndef __day11__zs__ #define __day11__zs__ #include <stdio.h> int sum(int v1, int v2) ...
- udev详解【转】
本文转载自:http://blog.csdn.net/skyflying2012/article/details/9359185 如果你使用Linux比较长时间了,那你就知道,在对待设备文件这块,Li ...
- [源码管理] Microsoft Visual SourceSafe 2005 下载与配置
一.VSS2005的下载地址是:百度搜索关键字:vss, 二.配置Microsoft Visual SourceSafe 2005的Internet访问 VSS2005发布以后,早就听说可以支持Int ...
- linux系统在线搭建禅道
1.先安装wget:yum -y install wget 2.下载安装禅道:[root@zhaowen ~]# wget http://dl.cnezsoft.com/zentao/9.0.1/Ze ...
- 关于一些UI的插件(杂)
1.时间插件 //日期框 $('.date-picker').datepicker(); 2.checkbox 保存checkbox的值 // 组装选择的标签 var check = $(" ...
- Dalvik 堆内存管理与回收
Dalvik虚拟机用来分配对象的堆划分为两部分,一部分叫做Active Heap,另一部分叫做Zygote Heap.下面基于管理机制来介绍为何分配为这两部分,以及堆内存的管理. 我们从Android ...
- js 找数组中的最值
背景: 2个数组以下 , 比如 [[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]] 找最值的时候, ...
- javaweb 之 代理模式
一.动态代理 1.1.代理模式 什么是代理模式及其作用 Proxy Pattern(即:代理模式),23种常用的面向对象软件的设计模式之一 代理模式的定义:为其他对象提供一种代理以控制对这个对象的访问 ...
- MySQL 5.6 Reference Manual-14.3 InnoDB Transaction Model and Locking
14.3 InnoDB Transaction Model and Locking 14.3.1 InnoDB Lock Modes 14.3.2 InnoDB Record, Gap, and Ne ...