Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B
1 second
256 megabytes
standard input
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.
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.
2
1 2
1 1
3
1 4 5
4 1
5
3 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.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
wa了无数次啊,这题到处是坑,不过题目真心不错
一开始看不懂题意,什么“maximum beauty difference”,这什么意思???看了N久,原来是花的最大魅力值差
好吧,一下有思路,没看数据量,wa了一次long long
然后又wa了一次脑抽筋
然后又wa了一次特判
然后又wa了一次全部相同的情况
…………
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std; int main()
{
long long maxx=,minn=,i,j;//wa one
int str[];
int n;
while(scanf("%d",&n)!=EOF)
{
minn=,maxx=;
for(int i=; i<n; i++)
scanf("%d",&str[i]);
sort(str,str+n);
printf("%d ",str[n-]-str[]);
//minn=str[0],maxx=str[0];
for(i=; i<n; i++)
{
if(str[i] == str[])
{
minn++;
}
else break;
}
for(i=n-; i>=; i--)
{
if(str[n-] == str[i])
maxx++;
else break;
}
//if(str[n-1] == str[0])printf("1\n");//wa 2
//else
if(n == && str[] == str[])//wa 3
printf("1\n");
else if(str[] != str[n-])
printf("%I64d\n",maxx*minn);
else if(str[] == str[n-])
printf("%I64d\n",maxx*(maxx-)/);//wa 4
}
return ;
}
Codeforces Round #261 (Div. 2) B的更多相关文章
- Codeforces Round #261 (Div. 2)[ABCDE]
Codeforces Round #261 (Div. 2)[ABCDE] ACM 题目地址:Codeforces Round #261 (Div. 2) A - Pashmak and Garden ...
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
http://codeforces.com/contest/459/problem/E 不明确的是我的代码为啥AC不了,我的是记录we[i]以i为结尾的点的最大权值得边,然后wa在第35 36组数据 ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
- Codeforces Round #261 (Div. 2) - E (459E)
题目连接:http://codeforces.com/contest/459/problem/E 题目大意:给定一张有向图,无自环无重边,每条边有一个边权,求最长严格上升路径长度.(1≤n,m≤3 * ...
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B 题意: 给出n支花,每支花都有一个漂亮值.挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且 ...
- Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)
题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 seco ...
- Codeforces Round 261 Div.2 E Pashmak and Graph --DAG上的DP
题意:n个点,m条边,每条边有一个权值,找一条边数最多的边权严格递增的路径,输出路径长度. 解法:先将边权从小到大排序,然后从大到小遍历,dp[u]表示从u出发能够构成的严格递增路径的最大长度. dp ...
- Codeforces Round 261 Div.2 D Pashmak and Parmida's problem --树状数组
题意:给出数组A,定义f(l,r,x)为A[]的下标l到r之间,等于x的元素数.i和j符合f(1,i,a[i])>f(j,n,a[j]),求有多少对这样的(i,j). 解法:分别从左到右,由右到 ...
- Codeforces Round #261 (Div. 2)
第一场难得DIV2简单+AK人数多: E:给出一张图,求最多的边数,满足:在这个边的集合中后面的边的权值大于前面的边; 思路:我们将图按权值排列,以为只可能边权值小的跟新权值大的所以对于一条边我们只跟 ...
随机推荐
- 关于jQuery的bind()\trigger()\triggerHandler()
1.bind() 事件绑定. 多个事件会链式累加,而不会覆盖. 即 $("div").bind("click",funtion(){alert("te ...
- RAII惯用法详解
[1]什么是RAII惯用法? RAII是Resource Acquisition Is Initialization的缩写,意为“资源获取即初始化”. 它是C++之父Bjarne Stroustrup ...
- Tutorial: WPF User Control for AX2012
原作者: https://community.dynamics.com/ax/b/goshoom/archive/2011/10/06/tutorial-wpf-user-control-for-ax ...
- 使用composer构建PHP框架怎么把Redis引入
选择 nrk/predis 作为 Redis 驱动,修改composer.json增加一个 require 项: "predis/predis": "*" 运行 ...
- 对Discuz的简单认识
Discuz是php的一个开源论坛系统,是由康盛创想公司2004开发,从Discuz! 1.0到 现在的Discuz X3,无论从功能上还是从用户体验上,都达到了一个质的飞越.主要包括论坛.门户.群组 ...
- [HTML]js动态修改表格里面的内容
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/T ...
- css基本样式总结
1:背景(background) <!DOCTYPE html> <html> <head lang="en"> <meta charse ...
- hdu 2053 Switch Game 水题一枚,鉴定完毕
Switch Game Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- UML中的用例(Use Case)概念分析及StarUML实例
在UML中use case似 乎最簡單的,用例建模的最主要功能就是用来表达系统的功能性需求或行为,依我的理解用例建模可分为用例图和用例描述.用例图由参与者(Actor).用例 (Use Case).系 ...
- Solr开发文档
转载:http://www.cnblogs.com/hoojo/archive/2011/10/21/2220431.html Solr 是一种可供企业使用的.基于 Lucene 的搜索服务器,它支持 ...