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;
}
(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;
}
相关文章推荐
- 浏览器是怎样工作的:渲染引擎,HTML解析(连载二)
- Javascript 基础之Array对象
- javascript操作DOM--添加、删除节点的简单实例
- Javascript 基础之String对象
- Gson解析Json
- js 变量声明(显隐声明,声明提前)
- A标签-一个按钮样式
- js原生态开发需要掌握的几个要点
- CSS3 box-shadow
- bootstrap tab切换如何让鼠标移动自动切换内容
- jQuery Event.delegateTarget属性详解
- 用Sublime 3作为React Native的开发IDE
- [转]JqueryEasyUI教程入门篇
- HTML5新增主题结构
- React Native 学习笔记(二)
- Extjs使用Kindeditor编辑套打样式
- select2 搜索下拉框的用法
- MalformedJsonException
- react native ES6语法规则记录
- PubSubJS简介,一个利用JavaScript进行发布/订阅的库