题意:给定 n 个数,让你找出一个排列满足每个数相邻作差之和最大,并且要求字典序最小。

析:这个表达式很简单,就是把重新组合一下,就成了x1-xn,那么很简单,x1是最大的,xn是最小的,中间排序就好。

代码如下:

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring> using namespace std;
const int maxn = 100 + 5;
int a[maxn]; int main(){
int n;
cin >> n;
int ans = 0;
for(int i = 0; i < n; ++i){
cin >> a[i];
//if(a[i] == i) ++ans;
}
sort(a, a+n);
printf("%d", a[n-1]);
for(int i = 1; i < n-1; ++i)
printf(" %d", a[i]);
printf(" %d\n", a[0]);
return 0;
}

CodeForces 347A Difference Row (水题)的更多相关文章

  1. codeforces 347A - Difference Row

    给你一个序列,让你求(x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).值最大的一个序列,我们化简一下公式就会发现(x1 - x2) + (x2 - x3) + . ...

  2. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  3. codeforces 706A A. Beru-taxi(水题)

    题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...

  4. codeforces 569B B. Inventory(水题)

    题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces 489A SwapSort (水题)

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. codeforces 688A A. Opponents(水题)

    题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  7. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

  8. Codeforces Gym 100286I iSharp 水题

    Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  9. codeforces A. Difference Row

    link:http://codeforces.com/contest/347/problem/A 开始看起来很复杂的样子,但是刚写下样例,就发现因为中间的都消去了,其实起作用的就是最大值和最小值=_= ...

随机推荐

  1. Java 版本6下载大全

    Oracle 官方 JDK6 下载地址: 基本包含所有的JDK6版本. 需要登注册相应的账户登录到Oracle官网~ http://www.oracle.com/technetwork/java/ja ...

  2. List、Set、Map下各类型的对比

    1.List和Set: List: 元素有放入顺序,元素可重复,查找效率高,插入删除效率低: Set: 元素无放入顺序,元素不可重复,(元素虽然无顺序,但元素在Set中的位置是由该元素的HashCod ...

  3. 利用docker 最新漏洞渗透--提取root 权限

    一.事出 近期乌云漏洞平台等科技新闻,爆出Docker虚拟化 端口漏洞,本着热爱开源,实践动手的精神,我也去尝试了下,漏洞严重性确实很高,可以拿到root 登陆账户. 二.还原 2.1 通过扫描,我们 ...

  4. Promise题目

    setTimeout(function () { console.log(1); }, 0) new Promise(function executor(resolve) { console.log( ...

  5. 给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组

    Array.prototype.removeCount=function(){ var that=this; var arr=[]; for(var i=0;i<that.length;i++) ...

  6. azkaban平台的使用

    最近接触一些大数据的测试,有些hadoop/spark任务在服务器测试不太方便,会放到azkaban上跑 简单写下azkaband的使用流程:包括任务的上传和提交任务到hadoop集群 一 登陆azk ...

  7. [转] C#中out和ref之间的区别

    gskcc 的原文地址 C#中out和ref之间的区别 首先:两者都是按地址传递的,使用后都将改变原来参数的数值. 其次:ref可以把参数的数值传递进函数,但是out是要把参数清空,就是说你无法把一个 ...

  8. 正则表达式RE与扩展正则表达式ERE——grep与egrep

    grep 正则表达式规则: ^ 行首定位符,表示从行首开始进行模式匹配 . 一个非换行符的字符 [ ] 匹配属于此集合的任意一个字符 [^ ] 匹配不属于此集合的任意一个字符 [a-z] (其指定的集 ...

  9. adb命令检测apk启动时间、内存、CPU使用情况、流量、电池电量等——常用的adb命令

    ADB:Android Debug Bridge,是Android SDK里一个可以直接操作安卓模拟器或真实设备的工具,颇为强大.   检测APP:   adb shell am start -W p ...

  10. Oracle的Spool导出数据

    出自:http://wallimn.iteye.com/blog/472182 实践 只能在一个终端上的一个窗口中进行操作 第一步:连接oracle数据库     sqlplus qkp/mm_eft ...