跳过正文
  1. Posts/

codeforces #314 A. Lineland Mail

·208 字·1 分钟

给一个有序序列,问对于没一个数,和它相差最少和最多的数的位置。

 1/*************************************************************************
 2	> File Name: code/cf/#314/A.cpp
 3	> Author: 111qqz
 4	> Email: rkz2013@126.com
 5	> Created Time: 2015年08月06日 星期四 00时01分51秒
 6 ************************************************************************/
 7
 8#include<iostream>
 9#include<iomanip>
10#include<cstdio>
11#include<algorithm>
12#include<cmath>
13#include<cstring>
14#include<string>
15#include<map>
16#include<set>
17#include<queue>
18#include<vector>
19#include<stack>
20#define y0 abc111qqz
21#define y1 hust111qqz
22#define yn hez111qqz
23#define j1 cute111qqz
24#define tm crazy111qqz
25#define lr dying111qqz
26using namespace std;
27#define REP(i, n) for (int i=0;i<int(n);++i)
28typedef long long LL;
29typedef unsigned long long ULL;
30const int inf = 0x7fffffff;
31const int N=2E5+7;
32LL a[N];
33int main()
34{
35    int n;
36    cin>>n;
37    a[0]=-inf;
38    a[n+1]=inf;
39
40    for ( int i  = 1 ; i <= n ; i ++ )
41    {
42	cin>>a[i];
43    }
44    int mx = -1;
45    int mi = inf;
46    cout<<a[2]-a[1]<<" "<<a[n]-a[1]<<endl;
47    for ( int i = 2 ; i <= n-1 ; i++ )
48    {
49	cout<<min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i]))<<" "<<max(abs(a[i]-a[1]),abs(a[n]-a[i]))<<endl;
50    }
51    cout<<a[n]-a[n-1]<<" "<<a[n]-a[1]<<endl;
52	return 0;
53}
🏛️ 111qqz 的技术博客 · 15 年博客历史 (2011 - 2026)
发布于 2015-08-05

💡 觉得有启发?欢迎互动交流!

如果你在阅读、编译运行或系统优化中有任何疑问、思考或更好的解法,欢迎在下方发表评论,或通过邮件直接探讨。

本文链接:https://111qqz.com/2015/08/cf314a/ 知识共享署名-非商业性使用 4.0 国际许可 (CC BY-NC 4.0)

相关文章

cf 443B Kolya and Tandem Repeat

·441 字·1 分钟
B. Kolya and Tandem Repeat time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.

poj 3279 Fliptile (搜索..暴力?)

·982 字·2 分钟
http://poj.org/problem?id=3279 反转类问题. 有N*M个方格,每个上面有数字0或者1 操作一个方格,这个方格即其相邻的四个方格(有公共边)会改变状态(由0变1或者由1变0)