B. Pashmak and Flowers
来源:互联网 发布:淘宝代运营 猪八戒网 编辑:程序博客网 时间:2024/05/21 09:54
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.
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).
The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
21 2
1 1
31 4 5
4 1
53 1 2 3 1
2 4
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.
解题说明:此题是找出一列数中差值最大的一对数,很显然是找出该数列中的最大数和最小数。由于可能存在多个最大数和最小数,在构造不同的配对时,只需要保证每个配对中有一个数字不同即可,是个简单的排列组合问题。要注意的是,如果该数列中所有数都相同,那么就是C(n,2)
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstdlib>#include<cstring>using namespace std;int main(){long long int n;long long int b[200000];long long int i=0,j=0,k=0,n1=1,n2=1;scanf("%lld",&n);for(i=0;i<n;i++){scanf("%lld",&b[i]);}j=b[0];k=b[0];for(i=1;i<n;i++){if(b[i]>j){j=b[i];n1=1;}else if(b[i]==j){n1++;}if(b[i]<k){k=b[i];n2=1;}else if(b[i]==k){n2++;}}if(j!=k){printf("%lld %lld\n",j-k,n1*n2);}else{printf("%lld %lld\n",j-k,(n1*(n1-1))/2);}return 0;}
- B. Pashmak and Flowers
- B. Pashmak and Flowers
- B. Pashmak and Flowers
- 459B Pashmak and Flowers
- 【CODEFORCES】 B. Pashmak and Flowers
- #261B. Pashmak and Flowers
- Codeforces 459B Pashmak and Flowers(水题)
- CodeForces 459B. Pashmak and Flowers
- Codeforces 459B Pashmak and Flowers
- CodeForces 459B Pashmak and Flowers
- codeforces 459B Pashmak and Flowers
- cf459B Pashmak and Flowers
- Pashmak and Flowers
- Codeforces Round #261 (Div. 2)B. Pashmak and Flowers
- Codeforces #261 (Div. 2)B. Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B.Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers【水】
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers
- 1282 - Cyin的工资
- VC设置静态文本控件的显示字体和显示内容
- C++继承问题
- Android & Linux的suspent和resume执行流程
- 用thinpkphp内容编码错误
- B. Pashmak and Flowers
- 几千微信好友是这样来的
- projecteuler---->problem=36----Double-base palindromes
- ICETEK-OMAPL138运行校准触摸屏程序后,只能点击第一个点,其他点无法点击
- 权限检测_相机_麦克风
- s3c2440通过GPIO口控制三块74HC595
- Linux操作系统C语言获取IP
- Sphinx学习之sphinx的安装篇
- IPsec VPN数据传输过程