Codeforce 567A - Lineland Mail
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, andmaxi 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 n distinct 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 12
3 9
4 7
5 12
2
-1 1
2 2
2 2
思路:
找出n个城市坐标最大和最小的点,对于第i个城市来说,花费最大的是到坐标最大的点或坐标最小的点,花费最小是到第i-1或i+1个点,记录所有的结果,并输出
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long LL;
const int N=;
const int mod=1e9+;
LL a[] , l , r ;
int main() {
int i , n ;
scanf("%d", &n) ;
for(i = ; i < n ; i++)
scanf("%I64d", &a[i]) ;
l = a[] ;
r = a[n-] ;
printf("%I64d %I64d\n", a[]-a[] , r - a[] ) ;
for(i = ; i < n- ; i++) {
printf("%I64d %I64d\n", min(a[i]-a[i-],a[i+]-a[i]) , max(a[i]-l,r-a[i]) ) ;
}
printf("%I64d %I64d\n", a[n-]-a[n-], a[n-]-l ) ;
return ;
}
最新文章
- JS中 call() 与apply 方法
- [Java 进阶]异常
- 浅谈压缩感知(三十):压缩感知重构算法之L1最小二乘
- iTween_ValueTo函数
- UITableView的分割线不满屏的解决方法
- WINDOWS操作系统中可以允许最大的线程数(线程栈预留1M空间)(56篇Windows博客值得一看)
- Unity--关于优化方面的那些事儿(一)
- FineUIMvc随笔 - 不能忘却的回发(__doPostBack)
- react实现双向绑定
- plsql本机不安装数据库连接远程数据库
- 【Java学习笔记之二】java标识符命名规范
- iOS-image图片压缩
- Springboot项目配置druid数据库连接池,并监控统计功能
- 软件测试-homework3
- (原)DropBlock A regularization method for convolutional networks
- D - C Looooops POJ - 2115 欧几里德拓展
- Java 求两个数百分比%
- BZOJ5018:[SNOI2017]英雄联盟(背包DP)
- leetcode485
- Python之reduce函数