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 ...
随机推荐
- win10安装Anaconda+TensorFlow+配置PyCharm
其实很简单,我这里也只是记录一下而已. 第一大坑:anaconda必须安装4.2以前的版本,不能安装4.3以后的 版本:满满的血泪史 因为我们需要安装自带的python必须是3.5,才可以调用Tens ...
- (转)OutOfMemory时抓取heap 快照
转自:https://testerhome.com/topics/579 首先说一下,在程序没有崩溃的时候如何抓取heap快照.这个大家应该都知道,在ddms中自带此功能. 见上图首先我们选中一个 ...
- python -- day 11 考试题
1. 文件t1.txt里面的内容为:(6分) 1,alex,22,13651054608,IT 2,wusir,23,13304320533,Tearcher 3,taibai,18,13332353 ...
- 转载-STM32片上FLASH内存映射、页面大小、寄存器映射
原文地址:http://blog.chinaunix.net/uid-20617446-id-3847242.html 本文以STM32F103RBT6为例介绍了片上Flash(Embedded Fl ...
- MySQL基本语句优化10个原则
在数据库应用中,程序员们通过不断的实践总结了很多经验,这些经验是一些普遍适用的规则.每一个程序员都应该了解并记住它们,在构造SQL语句时,养成良好的习惯.以下10条比较重要的原则供大家参考. 原则1: ...
- POJ2195 Going Home —— 最大权匹配 or 最小费用最大流
题目链接:https://vjudge.net/problem/POJ-2195 Going Home Time Limit: 1000MS Memory Limit: 65536K Total ...
- asp.net cookie and session
客户端只保存session id,信息存在服务端 Session状态应该存储在两个地方,分别是客户端和服务器端. 客户端只负责保存相应网站的SessionID,而其他的Session信息则保存在服务器 ...
- YTU 2451: 股市风云
2451: 股市风云 时间限制: 1 Sec 内存限制: 128 MB 提交: 37 解决: 25 [提交][状态][讨论版] 题目描述 股市强烈动荡,有涨有跌.现在有一组数据表示各公司的涨跌(涨 ...
- MYSQL进阶学习笔记四:MySQL存储过程之定义条件,处理过程及存储过程的管理!(视频序号:进阶_11,12)
知识点五:MySQL存储过程之定义条件和处理过程及存储过程的管理(11,12) 定义条件和处理: 条件的定义和处理可以用来定义在处理过程中遇到的问题时相应的处理步骤. DECLARE CONTINUE ...
- java停止线程
本文将介绍jdk提供的api中停止线程的用法. 停止一个线程意味着在一个线程执行完任务之前放弃当前的操作,停止一个线程可以使用Thread.stop()方法,但是做好不要使用它,它是后继jdk版本中废 ...