Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力
#B. HDD is Outdated Technology
##题目连接:
http://www.codeforces.com/contest/612/problem/B
##Description
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.
Find the time need to read file split to n fragments. The i-th sector contains the fi-th fragment of the file (1 ≤ fi ≤ n). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the n-th fragment is read. The fragments are read in the order from the first to the n-th.
It takes |a - b| time units to move the magnetic head from the sector a to the sector b. Reading a fragment takes no time.
##Input
The first line contains a positive integer n (1 ≤ n ≤ 2·105) — the number of fragments.
The second line contains n different integers fi (1 ≤ fi ≤ n) — the number of the fragment written in the i-th sector.
##Output
Print the only integer — the number of time units needed to read the file.
##Sample Input
3
3 1 2
##Sample Output
3
##Hint
##题意
给你n个数,一开始你在1,然后要走到2,然后走到3
问你最后他走到n的时候,花费多少
题解:
直接存一下每个值所在的位置,然后扫一遍就好了
代码
#include<bits/stdc++.h>
using namespace std;
int b[300000];
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int x;scanf("%d",&x);
b[x]=i;
}
long long ans = 0;
for(int i=1;i<n;i++)
ans+=abs(b[i+1]-b[i]);
cout<<ans<<endl;
}
Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力的更多相关文章
- Educational Codeforces Round 4 B. HDD is Outdated Technology
题目链接:http://codeforces.com/problemset/problem/612/B 解题思路: 一开始看错了题意,他要求的是从1-n所耗费的时间,n表示的是数值而不是下标, 实现代 ...
- Educational Codeforces Round 1 B. Queries on a String 暴力
B. Queries on a String Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/59 ...
- Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分
A. Diplomas and Certificates time limit per test 1 second memory limit per test 256 megabytes input ...
- Educational Codeforces Round 22 B. The Golden Age(暴力)
题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...
- Educational Codeforces Round 15 A, B , C 暴力 , map , 二分
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 6 B. Grandfather Dovlet’s calculator 暴力
B. Grandfather Dovlet’s calculator Once Max found an electronic calculator from his grandfather Do ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
随机推荐
- php动态生成一个xml文件供swf调用
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdo ...
- 如何配置仿真器DM8127+SEED-XDS560v2PLUS和连接不上的问题的解决
1 根据配置焊接JTAG电路转接板.我用的是14pin的. 2 安装仿真器驱动.安装完如下图 我安装的时候没有自动装上,第一次显示问号,后来手动的. 3 设置ccs工程 4 最后调试是这个样子 5 查 ...
- coroutine in c 备忘
coroutine: stackless和stackful jmp 基于switch的trick: http://www.chiark.greenend.org.uk/~sgtatham/corout ...
- 配置Texmaker中文支持
在Ubuntu 12.04 LTS下安装Texmaker后,如需要支持中文环境,需要安装CJK包. 终端(Ctrl+Alt+T(Terminal))下输入命令切换到超级管理员: sudo -i 安装包 ...
- JavaScript操作DOM的那些坑
js在操作DOM中存在着许多跨浏览器方面的坑,本文花了我将近一周的时间整理,我将根据实例整理那些大大小小的“坑”. DOM的工作模式是:先加载文档的静态内容.再以动态方式对它们进行刷新,动态刷新不影响 ...
- Web服务器与Servlet容器
今日要闻: Oracle启动了JRE7到JRE8的自动更新, JRE8发布于2014.3,于2014.10成为java.com默认版本, JRE7发布于2011.7, Oracle指定的Java生命政 ...
- 在fedora20下配置hadoop2.5.1的eclipse插件
(博客园-番茄酱原创) 在我的系统中,hadoop-2.5.1的安装路径是/opt/lib64/hadoop-2.5.1下面,然后hadoop-2.2.0的路径是/home/hadoop/下载/had ...
- 轻松学习Linux系统安装篇之fdisk命令行工具的使用
fdisk 的介绍: fdisk 命令是磁盘分区表操作工具:和以前Dos和windows下的分区工具功能一样:fdsik 能划分磁盘成为若干个区,同时也能为每个分区指定分区的文件系统 ...
- XE8 hash
c++builder xe8 hash calc md5.sha256.sha384.sha512 file and string sha256.sha384.sha512 must call l ...
- how to javafx hide background header of a tableview?
http://stackoverflow.com/questions/12324464/how-to-javafx-hide-background-header-of-a-tableview ———— ...