CF459B Pashmak and Flowers (水
Codeforces Round #261 (Div. 2)
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:
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 Output
1 1 Input
3 Output
4 1 Input
5 Output
2 4 Note
In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
|
题意:男主要选一对花送女主,要一只是值最大的花,一只是值最小的花,问有多少种选择。
题解:先找到最大值、最小值,统计最大值元素个数nma、最小值元素个数nmi,若最大值不等于最小值则直接出nma*nmi,若等于则出C(nma,2)。
注意运算很容易超int,还是全用long long比较保险。
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define usll unsigned ll
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) prllf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair ll n;
ll a[];
ll mi,ma,nma,nmi;
int main(){
ll i;
scanf("%I64d",&n);
mi=0xffffffff;
ma=;
REP(i,n){
scanf("%I64d",&a[i]);
mi=min(mi,a[i]);
ma=max(ma,a[i]);
}
nmi=;nma=;
REP(i,n){
if(a[i]==mi)nmi++;
if(a[i]==ma)nma++;
}
ll ans1=ma-mi;
ll ans2;
if(ans1!=)ans2=nma*nmi;
else ans2=(nmi)*(nmi-)/;
printf("%I64d %I64d\n",ans1,ans2);
return ;
}
CF459B Pashmak and Flowers (水的更多相关文章
- cf459B Pashmak and Flowers
B. Pashmak and Flowers time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Pashmak and Flowers
Pashmak decided to give Parmida a pair of flowers from the garden. There are nflowers in the garden ...
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- HDOJ(HDU) 1587 Flowers(水、、)
Problem Description As you know, Gardon trid hard for his love-letter, and now he's spending too muc ...
- codeforces 459 B.Pashmak and Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/459/B 题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beau ...
- CodeForces 459A Pashmak and Garden(水~几何-给两点求两点组成正方形)
题目链接:http://codeforces.com/problemset/problem/459/A 题目大意: 给出两个点(在坐标轴中),求另外两个点从而构成一个正方形,该正方形与坐标轴平行. 如 ...
- CF 459A && 459B && 459C && 459D && 459E
http://codeforces.com/contest/459 A题 Pashmak and Garden 化简化简水题,都告诉平行坐标轴了,数据还出了对角线,后面两个点坐标给的范围也不错 #in ...
- [codeforces] 暑期训练之打卡题(二)
每个标题都做了题目原网址的超链接 Day11<Given Length and Sum of Digits...> 题意: 给定一个数 m 和 一个长度 s,计算最大和最小在 s 长度下, ...
随机推荐
- 华硕笔记本之secure boot
在ubuntu下安装cuda的时候,一直装不好,cuda-7.5.run已经装好了,但是编译cuda的例程时失败,提示cuda的库链接不上. 初步判断是secure boot的问题,因为在开启X的情况 ...
- Linux_LVM_磁盘扩容
场景描述: 安装操作系统的时候,做了LVM,应用软件基本装在了“/”目录下,服务器运行一段时间后,该目录下的存储空间使用紧张,现利用LVM对其进行磁盘空间扩容. 注:安装系统的时候需要做逻辑卷管理,保 ...
- Android成长日记-仿跑马灯的TextView
在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢? ----------------------------------- ...
- 洛谷P2246 SAC#1 - Hello World(升级版)
题目背景 T1答案要mod1000000007(10^9+7),请重新提交,非常抱歉! 一天,智障的pipapi正在看某辣鸡讲义学程序设计. 题目描述 在讲义的某一面,他看见了一篇文章.这篇文章由英文 ...
- shell实现的守护进程
代码本来是别人那里拿来的,自己又改了下,给busybox用. #! /bin/sh PRO_PATH=/opt/myapp PROGRAM=packet_analyzer while true ; d ...
- iOS GCD中的dispatch_group
假如有一组任务,A,B,C,D,其中ABC是可以并行的,D是必须在ABC任务完成后再执行的. (举个场景,比如吃饭前必须先做菜.做饭和买饮料,然后才能开吃) 1.关于ABC的并行: 采用多线程的方式就 ...
- hihocoder 1356 分隔相同整数
时间限制:10000ms单点时限:1000ms内存限制:256MB 描述 给定一个包含N个整数的数组A.你的任务是将A重新排列,使得任意两个相等的整数在数组中都不相邻. 如果存在多个重排后的数组满足条 ...
- Untiy3D - 窗口界面1
记录Untiy3D学习中的英语单词 一.Project窗口下的英语单词 First Day Folder : 文件夹 C# Script : C#脚本 JavaScript:JS脚本 Editor T ...
- DNS(一)之禁用权威域名服务器递归解析
DNS dns是互联网中最核心的带层级的分布式系统,负责把域名解析成ip,把IP解析出域名,以及宣告邮件路由信息等等,使得使用域名访问网站,收发邮件成了可能. bind(berkeley Intern ...
- 通过System.getProperties()获取系统参数
Properties props=System.getProperties(); //系统属性 System.out.println("Java的运行环境版本:"+props ...