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 ...
随机推荐
- CentOS7 修改Jenkins以root用户运行
修改Jenkins以root用户运行,这在正式环境中是不可取的,但在自己的测试环境中就无所谓了啦,怎么方便怎么来. 1. 修改Jenkins配置文件1.1 修改$JENKINS_USER打开jenki ...
- 7.nth-of-type | nth-child?【CSS】
举例说明: <ul> <p>111</p> <span>222</span> <li>1</li> <li& ...
- 服务网关ZuulFilter过滤器--pre/post/error的用法(校验请求信息,获取路由后的请求/响应信息,处理服务网关异常)
微服务中Zuul服务网关一共定义了四种类型的过滤器: pre:在请求被路由(转发)之前调用 route:在路由(请求)转发时被调用 error:服务网关发生异常时被调用 post:在路由(转发)请求后 ...
- python之文件的相关操作
一..文件操作的函数 open("文件名(路径)" ,mode = "模式" , encoding="字符集") 注:文件路径: (1)绝对 ...
- JQuery EasyUI treegrid展开与折叠,以及数据加载两次的问题
问题:做项目的时候遇到代码生成的页面,只默认展开了一级节点,每次操作之后刷新还要手动一级一级展开,太麻烦了 官方API:http://www.jeasyui.net/plugins/186.html ...
- STM32+IAR 解决Error[Pe147]: declaration is incompatible with "__nounwind __interwork __softfp unsigned
在IAR中编译STM32工程,遇到 Error[Pe147]: declaration is incompatible with "__nounwind __interwork __soft ...
- Kotlin使用处协变的意义与用法
在上一次https://www.cnblogs.com/webor2006/p/11294849.html中对于Java的协变和Kotlin的协变提到了它们的区别,回忆一下: 其实在Kotlin中也有 ...
- 开源项目阅读笔记--appium+adb
git上搜了几个platform的代码,有一个项目给我感触挺深的. https://github.com/ThomasHansson/Appium-cross-platform-example/tre ...
- phpcms站点部署
1 wamp部署使用wamp2.4以下版本. 2.4版本自带的php5.4以上底层变化,phpcms运行不了. 2.2版自带的php5.3.10可以兼容. 2 安装配置时,尽量为每个站点配置(http ...
- 结构型模式(二) 桥接模式(Bridge)
一.动机(Motivation) 在很多游戏场景中,会有这样的情况:[装备]本身会有的自己固有的逻辑,比如枪支,会有型号的问题,同时现在很多的游戏又在不同的介质平台上运行和使用,这样就使得游戏的[装备 ...