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 长度下, ...
随机推荐
- Leetcode 280. Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] < ...
- [NOIP2012] 提高组 洛谷P1082 同余方程
题目描述 求关于 x 的同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入输出格式 输入格式: 输入只有一行,包含两个正整数 a, b,用一个空格隔开. 输出格式: 输出只有一行,包含一个正 ...
- Linux Programe/Dynamic Shared Library Entry/Exit Point && Glibc Entry Point/Function
目录 . 引言 . C/C++运行库 . 静态Glibc && 可执行文件 入口/终止函数 . 动态Glibc && 可执行文件 入口/终止函数 . 静态Glibc & ...
- iOS开发者账号配置进行设备调试
PS:我特么写了这么久,居然图片消失了,服了. 问题一:苹果开发者账号类型: 分为三种:个人的(99美金一年).组织的(99美金一年)和企业账号(299美金一年),申请时需要信用卡,可以找淘宝的代理申 ...
- RNN 入门教程 Part 3 – 介绍 BPTT 算法和梯度消失问题
转载 - Recurrent Neural Networks Tutorial, Part 3 – Backpropagation Through Time and Vanishing Gradien ...
- Handler,Thread,Looper之间关系小结
http://blog.csdn.net/sunxingzhesunjinbiao/article/details/6794840 (1) Looper类别用来为一个线程开启一个消息循环.默认情况下A ...
- 《JavaScript权威指南》学习笔记 第四天 数组
昨天学习了js的对象,了解了js的原型链.在js里面万事万物皆对象,只不过一些原始类型要经过包装对象的包装才能暂时变为对象.数组的本质是什么呢?数组其实就是一组数,也就是链表.每个数只是这个链表上的一 ...
- iOS - NSError用法规范
iphone跬步之--错误信息 NSError 一.获取系统的错误信息 比如移动文件时,获取文件操作错误: NSError *e = nil;[[NSFileManager defaultMana ...
- Java-IO之DeflaterOutputStream和InflaterOutputStream
此类为使用 "deflate" 压缩格式压缩数据实现输出流过滤器 example import java.io.File; import java.io.FileInputStre ...
- Nginx环境下http和https可同时访问方法
给nginx配置SSL证书之后,https可以正常访问,http访问显示400错误,nginx的配置如下: server { listen 80 default backlog=2048; liste ...