Codeforces Round #261 (Div. 2) 459B. Pashmak and Flowers(数学题,组合)
2014-08-16 21:15
471 查看
题目链接:http://codeforces.com/problemset/problem/459/B
B. Pashmak and Flowers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th
of them has a beauty number bi.
Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
The maximum beauty difference of flowers that Pashmak can give to Parmida.
The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
Input
The first line of the input contains n (2 ≤ n ≤ 2·105).
In the next line there are n space-separated integers b1, b2,
..., bn (1 ≤ bi ≤ 109).
Output
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Sample test(s)
input
output
input
output
input
output
Note
In the third sample the maximum beauty difference is 2 and there are 4 ways
to do this:
choosing the first and the second flowers;
choosing the first and the fifth flowers;
choosing the fourth and the second flowers;
choosing the fourth and the fifth flowers.
代码如下:
B. Pashmak and Flowers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th
of them has a beauty number bi.
Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
Your task is to write a program which calculates two things:
The maximum beauty difference of flowers that Pashmak can give to Parmida.
The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
Input
The first line of the input contains n (2 ≤ n ≤ 2·105).
In the next line there are n space-separated integers b1, b2,
..., bn (1 ≤ bi ≤ 109).
Output
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
Sample test(s)
input
2 1 2
output
1 1
input
3 1 4 5
output
4 1
input
5 3 1 2 3 1
output
2 4
Note
In the third sample the maximum beauty difference is 2 and there are 4 ways
to do this:
choosing the first and the second flowers;
choosing the first and the fifth flowers;
choosing the fourth and the second flowers;
choosing the fourth and the fifth flowers.
代码如下:
#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <cstdlib> #include <climits> #include <ctype.h> #include <queue> #include <stack> #include <vector> #include <utility> #include <deque> #include <set> #include <map> #include <iostream> #include <algorithm> using namespace std; const double eps = 1e-9; #define INF 1e18 //typedef long long LL; typedef __int64 LL; #define MAXN 200017 int main() { LL n; LL a[MAXN], b[MAXN]; while(~scanf("%I64d",&n)) { LL i; LL maxx = 0, minn = 1000000000; for(i = 0; i < n; i++) { scanf("%I64d",&a[i]); if(a[i] > maxx) maxx = a[i]; if(a[i] < minn) minn = a[i]; } LL cont1 = 0, cont2 = 0; if(maxx == minn) { printf("0 %I64d\n",n*(n-1)/2); continue; } for(i = 0; i < n; i++) { if(a[i] == maxx) cont1++; else if(a[i] == minn) cont2++; } LL d = maxx-minn; printf("%I64d %I64d\n",d,cont1*cont2); } return 0; }
相关文章推荐
- Codeforces #349 div1 C. Codeword 组合数学 递推
- Codeforces Round #361 (Div. 2) 题解 粗鲁地二分 组合数学提炼模型
- Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #362 (Div. 1) C PLEASE(组合数学,指数循环节)
- Codeforces Round #445 Div1 C:Maximum Element (组合数学+DP)
- Codeforces Round #324 (Div. 2) 584B. Kolya and Tanya 组合数学
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #447 (Div. 2) B. Ralph And His Magic Field(数论,组合数学)
- Codeforces Round #317 (Div. 2) C Lengthening Sticks (组合,数学)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Round #448 (Div. 2)D. String Mark(组合数学)
- Codeforces Round #404(Div. 2)D. Anton and School - 2【组合数学+思维】好题!好题!
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- 【组合数学】 Codeforces Round #295 (Div. 1) C - Pluses everywhere
- codeforces round 404 div2 D Anton and School - 2 组合数学
- CF#309-DIV2-C. Kyoya and Colored Balls-组合数学
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya(组合数学)
- Codeforces Round #439 (Div. 2) C. The Intriguing Obsession 组合数学
- Codeforces Beta Round #95 (Div. 2) C. The World is a Theatre 组合数学