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 ...
随机推荐
- ijkplayer详解AAA
https://www.jianshu.com/p/c5d972ab0309 https://www.android-arsenal.com/details/1/530 https://stackov ...
- layer获取弹出frame层数据
通常,弹出层关闭之前,需要将部分数据传入父页面.这个时候怎么办呢? 通过success获取frame层的index. 然后通过cancel事件,获取子页面数据. 拿获取高德地图坐标为例: // 显示地 ...
- VUEJS2.0源码理解--优
VUEJS2.0源码理解 http://jiongks.name/blog/vue-code-review/#pingback-112428
- [HTML] 微信wap开发---页面自适应大小
<meta name="viewport" content="width=device-width, initial-scale=0.5, minimum-scal ...
- Nginx实现负载均衡 + Keepalived实现Nginx的高可用
前言 使用集群是大中型网站解决高并发.海量数据问题的常用手段.当一台服务器的处理能力.存储空间不足时,不要企图去换更强大的服务器,对大型网站而言,不管多么强大的服务器,都满足不了网站持续增长的业务需求 ...
- centos6.6--------正向DNS配置
一.正向区: 将域名解析为IP====================================================================================注 ...
- C-概览
1.贝尔实验室的Dennis Ritchie在1972年开发了C语言,C来自于Ken Thompson的B语言.当时Ritchie正与 Thompson一起设计UNIX操作系统. 2.C是面向过程的编 ...
- let,const,var三者之间的区别
在ES6中新增了两种定义变量的命令let和const,在这之前相信大家都对var定义变量很熟悉,那么在了解ES6方法前, 1.我们先来回顾一下var定义变量的方法. 下面来看这段代码: for (va ...
- C# 2.0新加特性
泛型(Generics) 泛型是CLR 2.0中引入的最重要的新特性,使得可以在类.方法中对使用的类型进行参数化. 例如,这里定义了一个泛型类: class MyCollection<T> ...
- 创建一个dynamics CRM workflow (一) - Introduction to Custom Workflows
Workflow: Use this process to model and automate real world business processes. These processes can ...