• cf459B Pashmak and 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:

    1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
    2. 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 b1b2, ..., 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:

    1. choosing the first and the second flowers;
    2. choosing the first and the fifth flowers;
    3. choosing the fourth and the second flowers;
    4. choosing the fourth and the fifth flowers.

    这好像比A还水……输出极差,和两个数的差等于极差的方案数

    然后直接输出最大值的个数乘最小值的个数好像会wa……我会告诉你n个1的情况答案是n*(n-1)/2吗

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,mx,mn;
    int a[200010];
    long long ans,m1,m2;
    int main()
    {
    	n=read();
    	for (int i=1;i<=n;i++)a[i]=read();
    	sort(a+1,a+n+1);
    	mn=a[1];mx=a[n];
    	for (int i=1;i<=n;i++)
    	{
    	  if (a[i]==mx)m1++;
    	  if (a[i]==mn)m2++;
    	}
    	ans=m1*m2;if (mx==mn)ans=(long long)(n-1)*n/2;
    	printf("%d %lld",mx-mn,ans);
    }
    

      

    ——by zhber,转载请注明来源
  • 相关阅读:
    gulp管理静态资源缓存
    你懂AI吗(1)
    Vue.js之render函数基础
    笑看女程序员征婚SQL,半夜巡逻民警突然对我大喊int类型占几个字节
    高吞吐量的分布式发布订阅消息系统Kafka之Producer源码分析
    Java并没有衰落.大家对它的认识才刚刚开始 Java8全新出发
    那些面试官必问的JAVA多线程和并发面试题及回答
    在阿里一位新员工是怎么一步步培养起来的
    Lambda表达式用法大比较: Scala和Java 8
    国内外程序员编程网站、博客,对学编程的你提供一点小小的帮助
  • 原文地址:https://www.cnblogs.com/zhber/p/4035919.html
Copyright © 2020-2023  润新知