zoukankan      html  css  js  c++  java
  • 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,转载请注明来源
  • 相关阅读:
    并查集 [Total Eclipse]
    2020 Multi-University Training Contest 2 [The Oculus]
    2020牛客暑期多校训练营(第三场)G Operating on a Graph
    杭电多校第一场 [Fibonacci Sum]
    Codeforces Round #658 (Div. 2) E. Mastermind
    二次剩余
    SpringBlade 后端项目 部署 2.0-boot
    SpringBlade 前端项目 部署 Saber
    前端 天气插件
    SpringBlade 打包
  • 原文地址:https://www.cnblogs.com/zhber/p/4035919.html
Copyright © 2011-2022 走看看