CF

来源:互联网 发布:fc2新域名 编辑:程序博客网 时间:2024/04/27 15:59

2.中文题意概述:

在一条路上有 n 座城市。每座城市与你现在所处的位置的距离分别为 a1, a2, ..., an。保证a数组的值互不相同。

现在小L想知道,距离最近的两座城市之间的距离是多少,又有多少对城市之间的距离最近。

Input

第一行包含一个大整数 n (2 ≤ n ≤ 2·105).

第二行包含 n 个整数 a1, a2, ..., an ( - 109 ≤ ai ≤ 109). 保证所有 ai 互不相同。

Output

输出两个整数 — 最近的距离和距离最近的城市对数。

Example
Input
46 -3 0 4
Output
2 1
Input
3-2 0 2
Output
2 2
Note

第一个样例中最近的两个城市是第一座城市和第四座城市,距离为 |4 - 6| = 2。只有这两座城市之间的距离是2。

3.解题思路:

排序以后求相邻城市距离,用map维护一下最小值的个数。

4.AC代码:

#include <bits/stdc++.h>#define INF 0x7fffffff#define maxn 200100#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e exp(1.0)using namespace std;const int mod = 1e9 + 7;typedef long long ll;typedef unsigned long long ull;int a[maxn];map<int, int> mp;int main(){#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);long _begin_time = clock();#endifint n;while (~scanf("%d", &n)){mp.clear();for (int i = 0; i < n; i++)scanf("%d", &a[i]);sort(a, a + n);int ans_min = INF;for (int i = 1; i < n; i++){int res = a[i] - a[i - 1];mp[res]++;ans_min = min(ans_min, res);}printf("%d %d\n", ans_min, mp[ans_min]);}#ifndef ONLINE_JUDGElong _end_time = clock();printf("time = %ld ms.", _end_time - _begin_time);#endifreturn 0;}

0 0