A. Difference Row
2 seconds
256 megabytes
standard input
standard output
You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.
More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).
Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence x that corresponds to an arrangement of the largest possible value.
The first line of the input contains integer n (2 ≤ n ≤ 100). The second line contains n space-separated integers a1, a2, ..., an (|ai| ≤ 1000).
Print the required sequence x1, x2, ..., xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.
5
100 -100 50 0 -50
100 -50 0 50 -100
#include<stdio.h>
#include<stdlib.h>
int a[];
int comp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
} int main()
{
int n,i;
while(~scanf("%d",&n))
{
for(i = ;i < n;i ++)
scanf("%d",&a[i]);
qsort(a,n,sizeof(a[]),comp);
printf("%d ",a[n-]);
for(i = ;i < n-;i ++)
printf("%d ",a[i]);
printf("%d\n",a[]);
}
return ;
}
A. Difference Row的更多相关文章
- codeforces A. Difference Row
link:http://codeforces.com/contest/347/problem/A 开始看起来很复杂的样子,但是刚写下样例,就发现因为中间的都消去了,其实起作用的就是最大值和最小值=_= ...
- codeforces A. Difference Row 解题报告
题目链接:http://codeforces.com/problemset/problem/347/A 题目意思:给出一个序列 a1, a2, ..., an , 通过重排序列,假设变成 x1, x2 ...
- codeforces round #201 Div2 A. Difference Row
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- CodeForces 347A Difference Row (水题)
题意:给定 n 个数,让你找出一个排列满足每个数相邻作差之和最大,并且要求字典序最小. 析:这个表达式很简单,就是把重新组合一下,就成了x1-xn,那么很简单,x1是最大的,xn是最小的,中间排序就好 ...
- codeforces 347A - Difference Row
给你一个序列,让你求(x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).值最大的一个序列,我们化简一下公式就会发现(x1 - x2) + (x2 - x3) + . ...
- RGB 颜色空间转 HSI 颜色空间的matlab程序实现
RGB 颜色空间转 HSI 颜色空间的matlab程序实现 2014.10.20之前的内容有误,这里依据wikipedia更新了算法内容. 算法以wiki为准 https://en.wikipedia ...
- OLAP vs OLTP: what makes the difference
OLAP vs OLTP: what makes the difference OLPT and OLAP are complementingtechnologies. You can't live ...
- Difference between 'SAME' and 'VALID' padding
Difference between 'SAME' and 'VALID' padding 'SAME' padding 和 'VALID' padding 的区别 If you like ascii ...
- iOS7 UITableView Row Height Estimation
This post is part of a daily series of posts introducing the most exciting new parts of iOS7 for dev ...
随机推荐
- 一、VSTO概述
一.什么是VSTO? VSTO = Visual Studo Tools for Office,是.net平台下的Office开发技术.相对于传统的VBA(Visual Basic Applicati ...
- References & the Copy-Constructor
1 There are certain rules when using references: (Page 451) A reference must be initialized when it ...
- LINUX开机启动过程
LINUX开机启动过程 启动第一步--加载BIOS当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息 ...
- PHP问题
/usr/bin/ld: cannot find -lltdlcollect2: ld returned 1 exit statusmake: *** [libphp5.la] 错误 1 缺少libt ...
- win7下简单FTP服务器搭建
本文介绍通过win7自带的IIS来搭建一个只能实现基本功能的FTP服务器,第一次装好WIN7后我愣是没整出来,后来查了一下网上资料经过试验后搭建成功,其实原理和步骤与windows前期的版本差不多,主 ...
- WORDPRESS插件开发学习(一)HELLO WORLD
WORDPRESS插件开发学习系列文章第一篇,在每篇文章的后面追加固定的字符“Hello World” 一.打开wordpress目录->wp-content->plugins 二.在pl ...
- HTML 事件
1.HTML 全局事件属性 HTML4 的新特性之一就是可以使 HTML 事件触发浏览器中的行为,比方说当用户点击某个 HTML 元素时启动一段 JavaScript,在 HTML5 中还增加了一些新 ...
- hbuilder工具快捷键 http://www.qq210.com/shoutu/android
http://www.qq210.com/shoutu/android 创建HTML结构: h 8 (敲h激活代码块列表,按8选择第8个项目,即HTML代码块,或者敲h t Enter)中途换行: ' ...
- VMWare Workstation 占用443端口导致apache启动不了
中午安装vm,装linux 系统,搞了好几次才装成功,下午启动apache 忽然发现apache启动不了,各种郁闷啊,打开错误日志,NameVirtualHost无效,各种郁闷呐,试着修改端口,修改配 ...
- XML1_XML基础
1.XML的作用 XML 被设计用来传输和存储数据.所以XML 是不作为的. 2.简单的描述 XML 文档形成一种树结构. XML 文档必须包含根元素.该元素是所有其他元素的父元素.XML 文档中的元 ...