**hdu5495
来源:互联网 发布:股票数据分析流派 编辑:程序博客网 时间:2024/06/05 12:39
题目:
点击打开链接
题解:
a[i]和b[i]对应的值无论怎么移动都是一一对应的
目前想的还不是很明白,过两天想明白了过来更新
下面的代码超时
<pre name="code" class="html">#include <cstdio>#include <algorithm>#include <iostream>using namespace std; int a[100001]; int b[100001]; int c[100001]; int d[100001]; int t,n,x,ans;int main(){ cin>>t; while(t--) { cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; d[i]=0; } for(int i=1;i<=n;i++) { cin>>b[i]; } for(int i=1;i<=n;i++) { c[a[i]]=b[i]; } ans=n; for(int i=1;i<=n;i++) { int x=i; if(d[x]) continue; if(c[x]!=x) { ans--; while(!d[x]) { d[x]=1; x=c[x]; } } } printf("%d\n",ans); }}
0 0
- **hdu5495
- hdu5495
- HDU5495--LCS(置换群)
- 循环节 hdu5495 LCS
- BestCoder Round #58 (div.2)(hdu 5494,hdu5495,hdu5496)
- BestCoder Round #58 LCS 即hdu5495 (模拟)
- HDU5495求俩个1~n的数列按照相同的规则重排后的LCS
- 数据结构——排序(三)
- iOS移动开发之sqlite
- C#自动换ip功能或者ip代理功能要这么实现
- C#调用C++ dll的两种方法
- nyoj1237 最大岛屿 dfs求连通图
- **hdu5495
- Dijkstra’s shortest path algorithm
- 线程同步(synchronized关键字)
- Web前端技术:10个CSS经典技巧
- POJ 1128【并查集】
- 编程珠玑第二章习题—向量的旋转
- hashmap没看懂,先复制下来以后看
- Linux信号机制概述
- ROS中sensor_msgs/LaserScan Message消息的格式