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 ...
随机推荐
- 额。。。c++ sort()排序问题
首先呢 记得 这是个快排 不稳定 基本格式 头文件 #include<algorithm> #include<iostream> bool cmp(int x,int y) { ...
- 3.MVC基础-Code First 入门完整实例
1.添加一个EF的上下文类 EFDbContext public class EFDbContext:DbContext { public EFDbContext() : base("EF ...
- Flutter 实现图片裁剪
实现原理很简单 ,自己绘制一个裁剪框, 根据手势 选择到适合的位置 ,然后将选中的区域绘制到一个新的图片上,从而完成裁剪 裁剪框的绘制 这里我是根据点来连线的 因为每个点上会绘制一个拉伸的标识符 ...
- ArcEngine二次开发中运行出现There is no Spatial Analyst license currently available or enabled.
只需要在许可控件上勾选空间分析功能即可.
- ScheduledExecutorService周期性的定时任务
从j2se的api文档上查看ScheduledExecutorService的方法都是推迟一段时间然后相隔一段时间之后再去执行,没有想Timer定时器一样的可以在定点时间执行的api,如果也想像Tim ...
- 【CMDB】高级配置
思路: 一份默认配置,一份用户自定义配置,将两者结合,自定义优先级大于默认配置 目录结构 ''' 用户自定义的配置文件,settings.py ''' USER = 'xiaoming' PASSWO ...
- git注册和基本命令
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- php图形图像处理技术
图形图像处理技术,gd库的强大支持,PHP的图像可以是PHP的强项,PHP图形化类库,jpgraph是一款非常好用的强大的图形处理工具. 在PHP中加载GD库 gd官方网址下载: http://www ...
- python面试总结4(算法与内置数据结构)
算法与内置数据结构 常用算法和数据结构 sorted dict/list/set/tuple 分析时间/空间复杂度 实现常见数据结构和算法 数据结构/算法 语言内置 内置库 线性结构 list(列表) ...
- Shodan information gathering use parameter
1.we sue the Search Engines Shodan we can gather much information on the line web , such we want to ...