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 ...
随机推荐
- 【培训】交换机VLAN
为了解决用交换机做LAN互联无法限制广播的问题,出现了VLAN技术,把一个LAN划分为多个逻辑的“LAN”-VLAN. VLAN技术将一个物理的LAN逻辑地划分为不同的广播域,每一个VLAN包含一组有 ...
- 一次plsql 问题记录
环境 : window 7 x64 oracle 10.2g plsql 10.0.5 问题是 新装的 oracle10.2 plsql 一直连接不上 ,oracle_home 配置都对 .sql ...
- ubuntu下编译安装apache
官网http://httpd.apache.org/download.cgi下载apache源码包后 /*解包*/ gzip -d httpd-2_x_NN.tar.gz tar -xf httpd- ...
- ubuntu 安装 桌面 awesome
受了ubuntu 12.04自带的桌面,运行太卡了 http://www.linuxzen.com/awesometmuxgnomedoda-zao-gao-xiao-linuxzhuo-mian-h ...
- Linux网络应用编程之Packet Tracer安装及界面介绍
Packet Tracer入门 一,Packet Tracer介绍 packet tracer 是由Cisco公司发布的一个辅助学习工具,为学习思科网络课程的初学者去设计.配置.排除网络故障提供了网络 ...
- 强大的字符串格式化函数 - format
自python2.6开始,新增了一种格式化字符串的函数str.format(),它通过{}和:来代替% 位置方法格式化 >>>'{}-{}'.format('simon','ting ...
- hdu-A+B问题,大数加法
格式问题很头疼啊 Input The first line of the input contains an integer T(1<=T<=20) which means the num ...
- iBatis入手案例
第一部分,iBatis组织架构分析 1.1 组织架构图 1.2 架构分析 DAO层上面,DAO类通过SqlMapConfig文件,来构建iBatis提供的SqlMapClient,SqlMapConf ...
- 高级PHP应用程序漏洞审核技术
前言 PHP是一种被广泛使用的脚本语言,尤其适合于web开发.具有跨平台,容易学习,功能强大等特点,据统计全世界有超过34%的网站有php的应 用,包括Yahoo.sina.163.sohu等大型门户 ...
- linux 监控
http://www.iyunv.com/thread-50606-1-1.html http://segmentfault.com/a/1190000002537665 http://blog.cs ...