题目链接:http://codeforces.com/problemset/problem/612/B

解题思路:

一开始看错了题意,他要求的是从1-n所耗费的时间,n表示的是数值而不是下标,

实现代码:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std; #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=;while(q){if(q&)ans=ans*p;p=p*p;q>>=;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
struct node{
int num,id;
}a[];
bool cmp(const node x,const node y){
return x.num<y.num;
}
int main()
{
LL m,ans=,i;
cin>>m;
for(i=;i<=m;i++){
cin>>a[i].num;
a[i].id = i;
}
sort(a+,a++m,cmp);
for(i=;i<m;i++)
ans+=abs(a[i+].id-a[i].id);
cout<<ans<<endl;
}

Educational Codeforces Round 4 B. HDD is Outdated Technology的更多相关文章

  1. Educational Codeforces Round 4 B. HDD is Outdated Technology 暴力

    B. HDD is Outdated Technology 题目连接: http://www.codeforces.com/contest/612/problem/B Description HDD ...

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  8. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. android客服端+eps8266+单片机+路由器之远程控制系统

    用android客服端+eps8266+单片机+路由器做了一个远程控制的系统,因为自己是在实验室里,所以把实验室的门,灯做成了远程控制的. 控制距离有多远------只能说很远很远,只要你手机能上网的 ...

  2. [08] AOP基本概念和使用

    1.什么是AOP AOP = Aspect Oriental Programing,即面向切面编程.什么概念,我们看如下的图片: 三个方法中,重复使用了代码A和代码B,典型的场景比如"开启事 ...

  3. OpenGL初学:安装配置与第一个程序

    OpenGL初学:安装配置与第一个程序 2014年10月12日 12:37:03 process-z 阅读数:12413 标签: opengl安装教程 更多 个人分类: OpenGL   计算机图形学 ...

  4. java通过反射拷贝两个对象的同名同类型变量

    深拷贝和浅拷贝 首先对象的复制分为深拷贝和浅拷贝,关于这两者的区别,简单来说就是对于对象的引用,在拷贝的时候,是否会新开辟一块内存,还是直接复制引用. 两者的比较也有很多,具体可以看这篇文章: htt ...

  5. 51Nod 1668 非010串

    这是昨天上课ChesterKing dalao讲线代时的例题 当时看到这道题就觉得很水,记录一下后面两位的情况然后讨论一下转移即可 由于之前刚好在做矩阵题,所以常规的矩阵快速幂优化也很简单 好我们开始 ...

  6. Scala学习(七)练习

    控制结构和函数 1. 编写示例程序,展示为什么 package com.horstmann.impatient 不同于 package com package horstmann package im ...

  7. python 常见矩阵运算

    python 的 numpy 库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入 numpy 的包. 1.numpy 的导入和使用 from numpy import *;#导入numpy的 ...

  8. PowerBI开发 第十五篇:DAX 表达式(时间+过滤+关系)

    DAX表达式中包含时间关系(Time Intelligence)相关的函数,用于对日期维度进行累加.同比和环比等分析.PowerBI能够创建关系,通过过滤器来对影响计算的上下文. 一,时间关系 DAX ...

  9. Vue 实际项目中你可能会遇见问题

    纸上得来终觉浅,绝知此事要躬行! Vue的文档和教程看的太多,小的demo做的多,也不如自己实际的进行一个完整项目的开发.只有做了才知道原来问题这么多,这里列举了一些你做demo教程可能不会遇见的坑. ...

  10. BugkuCTF 计算器

    前言 写了这么久的web题,算是把它基础部分都刷完了一遍,以下的几天将持续更新BugkuCTF WEB部分的题解,为了不影响阅读,所以每道题的题解都以单独一篇文章的形式发表,感谢大家一直以来的支持和理 ...