知道了怎么置换之后,就可以用矩阵来置换了,但这道题一直关于置换的地方读不明白。

#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的更多相关文章

  1. 矩阵十题【五】 VOJ1049 HDU 2371 Decode the Strings

    题目链接:https://vijos.org/p/1049 题目大意:顺次给出m个置换,重复使用这m个置换对初始序列进行操作.问k次置换后的序列.m<=10, k<2^31. 首先将这m个 ...

  2. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  3. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. TextView高级

    前言 开门见山,这一篇博客主要讲一下在Android开发中,UI控件TextView的一些使用方式,并且通过四个例子实现一般项目中需要的效果来讲解TextView的使用.并且在之后的一段时间之内,都会 ...

  2. Adding a view

    在添加View之前,之前的页面是下面这个样子,需要注意的是浏览器标题,以及浏览器的内容 https://docs.asp.net/en/latest/tutorials/first-mvc-app/a ...

  3. ReflectionSugar 通用反射类

    http://www.cnblogs.com/sunkaixuan/p/4635710.html

  4. HP Z240组建磁盘阵列RAID1

  5. 一个php+jquery+json+ajax实例

    json.php <!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  6. python的模块导入

    单个文件导入:导入的模块可以是一个py文件(放置在当前文件的同级目录.默认路径等) 导入:import 模块名 使用:模块名.函数名 导入:from 模块名 import * 使用:函数名 ----- ...

  7. java selenium手动最大化chrome浏览器的方法

    package my_automation; import java.awt.Dimension; import org.openqa.selenium.Capabilities; import or ...

  8. Spark Scala语言学习系列之完成HelloWorld程序(三种方式)

    三种方式完成HelloWorld程序 分别采用在REPL,命令行(scala脚本)和Eclipse下运行hello world. 一.Scala REPL. windows下安装好scala后,直接C ...

  9. C# 添加应用程序包

    项目中可能会遇到某些扩展方法不可以应用的情况,这时候需要在项目中引用程序包 步骤如下: 回车即可

  10. 修复wordpress插件编辑器漏洞

    具体方法,将下面的代码添加到您的配置文件 wp-config.php中: define( 'DISALLOW_FILE_EDIT', true ); 以此关闭插件编辑器功能,一切就这么简单,漏洞也就不 ...