The puzzle
The puzzle:
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6489
找大佬讲了一下这道题,但还是不懂为什么要这样做,先记录一下以后再研究研究;
解题思路:
/* */
# include <bits/stdc++.h> using namespace std;
const int N=1e5 + ;
int pos[N]; int main()
{
int t;
scanf("%d", &t);
while( t-- )
{
int n;
scanf("%d", &n);
for( int i=; i<=n; i++ )
{
int x;
scanf("%d", &x);
pos[x] = i;
} int ans = ; for( int i=; i<=n; i++ )
{
while( pos[i]!=i )
{
swap(pos[i], pos[pos[i]] );
ans++;
}
}
printf("%d\n", ans);
}
return ;
}
The puzzle的更多相关文章
- Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net
Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...
- HDU5456 Matches Puzzle Game(DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...
- one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏
one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- POJ1651Multiplication Puzzle[区间DP]
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8737 Accepted: ...
- codeforce B Island Puzzle
B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- Ignatius's puzzle
Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- A hard puzzle
A hard puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 1097 A hard puzzle
Problem Description lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how ...
随机推荐
- 记录用到的mssql的几个方法
1.RIGHT ( character_expression , integer_expression ) 返回字符串中从右边开始指定个数的字符 character_expression 字符或二进制 ...
- NEST search查询
/// <summary> /// GET /megacorp/employee/_search /// </summary> /// <returns></ ...
- docker 容器和镜像常用命令整理
- 关于移动端图片浏览,previewimage的使用
我相信在移动端项目中,大家都会遇到图片浏览的问题,像qq,微信,微博,淘宝,当你点击图片时,图片会放大全屏显示,双击图片时图片继续放大查看,双指左右滑动也可以放大,当你再次点击时图片,图片恢复原始大小 ...
- js合并多个array
Array.prototype.concat.call(array1, array2, array3, ...)
- src属性与浏览器渲染
img标签 只要设置了src属性, 就会开始下载,因此可以使用这个特性,配合display:none,默默的下载一些图片,用的时候直接用,快了那么一丢丢~ 注意:不一定要添加到文档后才会开始下载,是只 ...
- oracle in和exists区别
in和exists http://oraclemine.com/sql-exists-vs-in/ https://www.techonthenet.com/oracle/exists.php htt ...
- vuex页面刷新数据丢失的解决办法
在vue项目中用vuex来做全局的状态管理, 发现当刷新网页后,保存在vuex实例store里的数据会丢失. 原因: 因为store里的数据是保存在运行内存中的,当页面刷新时,页面会重新加载vue实例 ...
- koa2安装
安装 1. npm install koa-generator -g 2. Koa2 test-koa2 3. npm install & npm run dev 看package.json里 ...
- 给定数字N,输出小于10^N的所有整数
讲起来比较简单,从0到N遍历输出就行了,但是如果N非常大,就涉及整数溢出问题,很明显是一个全排列问题,也就是输出N,代表N位上所有的数字取值是0-9,做一个全排列,还需要考虑的就是对于0001,006 ...