↓ Skip to main content
  1. Posts/

codeforces #314 A. Lineland Mail

·212 words·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

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

代码实现
 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}

Related

cf 443B Kolya and Tandem Repeat

·445 words·1 min
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. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat.

(BC 一周年)hdu 5311 Hidden String

·767 words·2 mins
http://acm.hdu.edu.cn/showproblem.php?pid=5311 题意:问能否从一个给定的字符串中拿出三个不相交的字串(原串可以有剩余),组成字符串“anniversary” 思路:暴力。 比赛的时候没做出来,sad 我发现我有一个问题,就是不敢跑暴力 有不少题其实正解就是暴力 或者有的题,暴力不是标解,但是绝对可A,可我就不敢写… 就觉得不会是这样.. 说到底还是不自信吧…

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

·986 words·2 mins
http://poj.org/problem?id=3279 反转类问题. 有N*M个方格,每个上面有数字0或者1 操作一个方格,这个方格及其相邻的四个方格(有公共边)会改变状态(由0变1或者由1变0) 问至少需要多少次操作,所有的状态都为0

codeforces 558c Amr and Chemistry (贪心)

·759 words·2 mins
http://codeforces.com/contest/558/problem/C 题目大意是说,给定N个数,可以对任意数进行任意次两种操作,×2,和/2(整除) 问最少操作多少次,可以让所有数相等。 嘛,前半个小时A掉了前两个提,d E貌似都是线段树。。并不会。。。就一直搞C。。。。