codeforces—— 567A —— Lineland Mail
来源:互联网 发布:淘宝发展前景怎么样 编辑:程序博客网 时间:2024/06/06 03:19
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position xi — a coordinate on the Ox axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in).
Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city.
For each city calculate two values mini and maxi, where mini is the minimum cost of sending a letter from the i-th city to some other city, and maxi is the the maximum cost of sending a letter from the i-th city to some other city
The first line of the input contains integer n (2 ≤ n ≤ 105) — the number of cities in Lineland. The second line contains the sequence of ndistinct integers x1, x2, ..., xn ( - 109 ≤ xi ≤ 109), where xi is the x-coordinate of the i-th city. All the xi's are distinct and follow in ascending order.
Print n lines, the i-th line must contain two integers mini, maxi, separated by a space, where mini is the minimum cost of sending a letter from the i-th city, and maxi is the maximum cost of sending a letter from the i-th city.
4-5 -2 2 7
3 123 94 75 12
2-1 1
2 22 2
问每个数与其余所有数,差值最小与差值最大
水题
#include<iostream>#include<cmath>#include<cstdio>#include<map>#include<set>#include<cstring>#include<string>#include<algorithm>#define MAX 2e9+8#define min(a,b) ((a)>(b)?(b):(a))using namespace std;int main(){ int n; while(cin>>n) { int temp=n,a[100008],b[100008]={MAX},SUM=0; while(temp--) cin>>a[temp]; sort(a,a+n); for(int i=1; i<n; i++) { b[i]=a[i]-a[i-1]; SUM+=b[i]; } b[n]=MAX; int sum=0; for(int i=0;i<n;i++) { cout<<min(b[i],b[i+1])<<' '<<max(SUM,sum)<<endl; sum+=b[i+1]; SUM-=b[i+1]; } } return 0;}
- codeforces—— 567A —— Lineland Mail
- CodeForces 567A-Lineland Mail
- Codeforces 567A Lineland Mail
- Codeforces 567A. Lineland Mail
- CodeForces 567A Lineland Mail
- CodeForces 567A Lineland Mail
- CodeForces 567A Lineland Mail
- codeforces 567A Lineland Mail
- Codeforces A. Lineland Mail
- CodeForces 567A Lineland Mail 贪心
- codeforces(567A)--A. Lineland Mail--B. Berland National Library
- Codeforces Round #Pi (Div. 2)567A Lineland Mail(模拟)
- A. Lineland Mail
- A. Lineland Mail-水题-Codeforces Round #Pi (Div. 2)
- Code Forces 567 A. Lineland Mail(水~)
- Lineland Mail
- 【codeforces】29C—Mail Stamps
- 【codeforces #3】A——BFS+贪心
- RabbitMQ消息队列(二):”Hello, World“
- 堡垒
- 日常关注测试牛人的blog
- Android NDK: From Elementary to Expert Expisode 21
- MySQL 命令行 备份、还原数据库 windows下
- codeforces—— 567A —— Lineland Mail
- 解决ajax的delete、put方法接受不到参数的问题
- 网狐6603全部架设过程棋牌平台开发搭建教程
- linux下网盘umount时报错"device is busy"的解决办法
- SourceInsight 直接打开当前文件所在文件夹
- Error:Unable to load class 'org.gradle.logging.StyledTextOutput'. Possible causes for this unexpecte
- Java设计模式之《组合模式》及应用场景(遍历指定路径下的文件目录和文件为例子)
- 提高codeing运行时间效率
- spring配置事务不起作用解决