【CodeForces 792A】New Bus Route
来源:互联网 发布:fft算法的作用 编辑:程序博客网 时间:2024/06/05 07:54
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.
46 -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.
思路:题目没什么好说的,很水,但被long long卡了3发。。。
定义INF时,4个3f是1e9,8个是1e18,注意此时用long long
#include <bits/stdc++.h>#define manx 200005typedef long long ll;const ll INF=0x3f3f3f3f3f3f3f3f;const int INF2=0x3f3f3f3f;using namespace std;int main(){ int a[manx]={0},n,cot; while(~scanf("%d",&n)){ ll minn=INF; for (int i=0; i<n; i++) scanf("%d",&a[i]); sort(a,a+n); for (int i=1; i<n; i++){ ll x=a[i]-a[i-1]; if (x < minn){ cot=1; minn=x; } else if (x == minn){ cot++; } } printf("%I64d %d\n",minn,cot); }// cout<<INF2<<endl<<INF<<endl;// 4个3f:1e9 1061109567// 8个3f:1e18 4557430888798830399 用long long return 0;}
- CodeForces 792A之New Bus Route
- 【CodeForces 792A】New Bus Route
- CodeForces 792A New Bus Route
- New Bus Route (Codeforces-792A)
- CF 792A New Bus Route 排序,模拟
- New Bus Rote codeforces
- 【CODEFORCES】 A. Bayan Bus
- Bus Route
- CodeForces 711A A. Bus to Udayland
- codeforces#71 A Bus Game----DFS
- Codeforces 435A Queue on Bus Stop
- codeforces-#475A. Bayan Bus(模拟)
- Codeforces 435A Queue on Bus Stop
- codeforces 711A.Bus to Udayland 【水题】
- Codeforces 711A Bus to Udayland
- 【模拟】Codeforces 711A Bus to Udayland
- Codeforces 711A- Bus to Udayland
- Codeforces-711A-Bus to Udayland
- tomcat端口被占用,解决方法
- SQL 小tips
- 服务器上Oracle System如何修改system用户密码
- 微信小程序开发—(八)canvas绘制图形
- OCX和DLL的区别
- 【CodeForces 792A】New Bus Route
- tomcat 的目录结构,servlet的配置与写法
- Python:tuple
- Oculus开发相关问题总结(一)Oculus登陆问题 Internal Error:OVR53225466
- javaweb:判断当前请求是否为移动设备访问
- Java多线程系列--“基础篇”01之 基本概念
- androidStudio快速打开工程
- word 2013中如何设置第几页共几页这种页码格式
- HttpServletRequestWrapper 实现xss注入(2)