您的位置:首页 > Web前端

CodeForces 347A Difference Row

2016-07-19 15:41 309 查看

(x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).

上式化简就是x[1]-x
嘛,中间的如果想按字典序排列,那就sort一下。

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
int a[110];
int main() {
int n; scanf ("%d",&n);
for (int i=0; i<n; i++) {
scanf ("%d",&a[i]);
}
sort(a,a+n);//x[1]-x
,then sort other numbers
printf("%d ",a[n-1]);//the largest one
for(int i=1;i<n-1;i++){printf("%d ",a[i]);}
printf("%d\n",a[0]);//the smallest one
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: