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 ;
}
Codeforce 567A - Lineland Mail的更多相关文章
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水
A. Lineland MailTime Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/proble ...
- Codeforces Round #Pi (Div. 2) A. Lineland Mail 水题
A. Lineland MailTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/567/probl ...
- codeforces Round #Pi (div.2) 567ABCD
567A Lineland Mail题意:一些城市在一个x轴上,他们之间非常喜欢写信交流.送信的费用就是两个城市之间的距离,问每个城市写一封信给其它城市所花费的最小费用和最大的费用. 没什么好说的.直 ...
- CodeForces 567A Gerald is into Art
http://codeforces.com/problemset/problem/567/A A. Lineland Mail time limit per test 3 seconds memory ...
- Codeforces Round #Pi (Div. 2) ABCDEF已更新
A. Lineland Mail time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #Pi (Div. 2)(A,B,C,D)
A题: 题目地址:Lineland Mail #include <stdio.h> #include <math.h> #include <string.h> #i ...
- ABP源码分析七:Setting 以及 Mail
本文主要说明Setting的实现以及Mail这个功能模块如何使用Setting. 首先区分一下ABP中的Setting和Configuration. Setting一般用于需要通过外部配置文件(或数据 ...
- Linux发邮件之mail命令
一.mail命令 1.配置 vim /etc/mail.rc 文件尾增加以下内容 set from=1968089885@qq.com smtp="smtp.qq.com" set ...
- php mail 函数发送邮件
当然你可以通过php ,在自己的站点制作一个反馈表单, 我这次的需求是用email 的形式发送数据报表,结构比较简单 // 收件人地址(此处只可以写一个地址,写多个地址,只有最后一个地址生效) $to ...
随机推荐
- PMP--2.1 商业论证(经济可行性研究报告)
####################################################### PS:半个月没有更新文档,因为是有点单线程,在整理启动过程组和规划过程组的内容,在规划规 ...
- AJAX优势、跨域方案及JSON数据格式和浏览器中JSON对象
ajax 不重新加载整个网页的情况下,更新部分网页的技术 注意:ajax只有在服务器上运行才能生效,我在本地一般用phpstudy 优点: 1.优化用户体验 2.承担了一部分本该服务器端的工作,减轻了 ...
- SAP 对HU做货物移动报错-Only 0 serial numbers entered instead of 30 -
SAP 对HU做货物移动报错-Only 0 serial numbers entered instead of 30 - 元旦刚过,就收到客户的业务人员报错说,当其对HU做转库(同一个公司代码下工厂到 ...
- 解决MySql客户端秒退(找不到my.ini)
问题说明(环境:windows7,MySql8.0) 今天安装好MySql后启动MySql服务-->启动服务都失败的就不要往下看了,自行百度解决. 打开客户端秒退,但在cmd中是可以使用数据库的 ...
- Linux 防SSH暴力攻击
在下这几天发现我的VPS 总是莫名遭受到 江苏镇江那边的IP 登录请求攻击 ,跟踪了下路由,发现ip是从蒙古那边出去的,然后意识到可能是有扫描端口的.. 方法一: 现在的互联网非常不安全,很多人没事就 ...
- ARC 064 F-Rotated Palindromes
题意 问有多少个长度为 \(N\) 且字符集大小为 \(K\) 的字符串可以通过回文串旋转 (把第一个字符移到最后)若干次得到.\(N,K\le 10^9\) 做法 设\(f_i\)为最小周期为\(i ...
- Visual Studio 2019新建Web项目
选择创建新项目 选择ASP.NET Web 应用程序,下一步 填好相关信息,位置是保存项目的位置,点击创建 创建你需要的项目项,我们这里选择空项目,点击创建 添加文件 右击项目名 -> 添加 - ...
- 有关配置网站时安装ZipArache的方法。
在配置网站初始化过程中,发现ZipArache需要启动,上网搜索了一番,发现安装ZipArache的步骤十分繁琐. 换一种思路,ZipArache作为PHP的拓展类,其名字首部有ZIP字样,那么可否直 ...
- 清北学堂—2020.1提高储备营—Day 1 afternoon(二分、分治、贪心)
qbxt Day 1 afternoon --2020.1.17 济南 主讲:李佳实 目录一览 1.二分法 2.分治 3.贪心 总知识点:基础算法 一.二分法 (1)算法分析:二分法是一种暴力枚举的优 ...
- PHP OOP
<?php //1. Class and object /* object-oriented concept an object can be almost any items or conce ...