Educational Codeforces Round 18 A
Description
There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to build a new bus route. The Minister doesn't want to spend large amounts of money — he wants to choose two cities in such a way that the distance between them is minimal possible. The distance between two cities is equal to the absolute value of the difference between their coordinates.
It is possible that there are multiple pairs of cities with minimal possible distance, so the Minister wants to know the quantity of such pairs.
Your task is to write a program that will calculate the minimal possible distance between two pairs of cities and the quantity of pairs which have this distance.
The first line contains one integer number n (2 ≤ n ≤ 2·105).
The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). All numbers ai are pairwise distinct.
Print two integer numbers — the minimal distance and the quantity of pairs with this distance.
4
6 -3 0 4
2 1
3
-2 0 2
2 2
In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance.
题意:问两点之间距离最小为多少,有几对距离最小的
解法:排序模拟
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
ll a[];
ll maxn=(<<)-;
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
sort(a+,a++n);
ll pos=a[];
for(int i=;i<=n;i++)
{
maxn=min(abs(a[i]-pos),maxn);
pos=a[i];
}
cout<<maxn<<" ";
ll ans=a[];
ll sum=;
for(int i=;i<=n;i++)
{
if(maxn==abs(a[i]-ans))
{
sum++;
}
ans=a[i];
}
cout<<sum<<endl;
return ;
}
Educational Codeforces Round 18 A的更多相关文章
- Educational Codeforces Round 18
A. New Bus Route 题目大意:给出n个不同的数,问差值最小的数有几对.(n<=200,000) 思路:排序一下,差值最小的一定是相邻的,直接统计即可. #include<cs ...
- Educational Codeforces Round 18 D
Description T is a complete binary tree consisting of n vertices. It means that exactly one vertex i ...
- Educational Codeforces Round 18 B
Description n children are standing in a circle and playing the counting-out game. Children are numb ...
- Educational Codeforces Round 18 C. Divide by Three DP
C. Divide by Three A positive integer number n is written on a blackboard. It consists of not more ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 40 F. Runner's Problem
Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
随机推荐
- 使用Axis2开发WebService
一.准备 1.下载Axis2.eclipse插件 axis2-1.6.2-war.zip: http://mirror.bjtu.edu.cn/apache//axis/axis2/java/core ...
- const *char p和char const *p
const *char p和char const *p,const char*p的区别 char*const p——p必须初始化,且不能指向别处,即p是指针常量: char const*p——p指向的 ...
- Thread Runnable 区别
[线程的并发与并行] 在单CPU系统中,系统调度在某一时刻只能让一个线程运行,虽然这种调试机制有多种形式(大多数是时间片轮巡为主),但无论如何,要通过不断切换需要运行的线程让其运行的方式就叫并发(co ...
- yum 安装 mysql
安装 yum -y install mysql-server 开机自启动 chkconfig mysqld on 设置账户密码 启动 service mysqld start -- 进入mysql库 ...
- weblogic 修改控制台console访问路径 url
出于安全的考虑需要对weblogic的console进行屏避,或者修改默认的访问路径,主要有两种方法:(这里针对weblogic8.1) 一.进入默认的控制台,例如“localhost/console ...
- 使用sql compare生成的sql语句
创建表以及主键 判断表是否存在 OBJECT_ID 判断主键是否存在 SELECT 1 FROM sys.indexes WHERE name = N'PK_LISA_NoUseWebpartRepl ...
- html5--6-35 列表和表格
html5--6-35 列表和表格 实例 学习要点 掌握列表和表格的样式设置 表格有关的属性: border-collapse 设置是否把表格边框合并为单一的边框.属性值:separate 默认值/c ...
- RPi 2B IPC webcam server
/**************************************************************************** * RPi 2B IPC webcam se ...
- 枚举子集 Codeforces306 Div2 B
题目 分析:用二进制法去枚举子集,同时判断满足条件的子集个数加1 #include "iostream" #include "cstdio" using nam ...
- NOIP2003题解
传送门 考查题型 搜索 字符串 模拟 dp T1 神经网络 题目背景 人工神经网络(Artificial Neural Network)是一种新兴的具有自我学习能力的计算系统,在模式识别.函数逼近及贷 ...