• Codeforces Round #261 (Div. 2) B


    链接:http://codeforces.com/contest/459/problem/B

    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 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
    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.

    &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    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=0,minn=0,i,j;//wa one
        int str[300010];
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            minn=1,maxx=1;
            for(int i=0; i<n; i++)
                scanf("%d",&str[i]);
            sort(str,str+n);
            printf("%d ",str[n-1]-str[0]);
            //minn=str[0],maxx=str[0];
            for(i=1; i<n; i++)
            {
                if(str[i] == str[0])
                {
                    minn++;
                }
                else break;
            }
            for(i=n-2; i>=0; i--)
            {
                if(str[n-1] == str[i])
                    maxx++;
                    else break;
            }
            //if(str[n-1] == str[0])printf("1
    ");//wa 2
            //else
            if(n == 2 && str[0] == str[1])//wa 3
                printf("1
    ");
            else if(str[0] != str[n-1])
                printf("%I64d
    ",maxx*minn);
            else if(str[0] == str[n-1])
                printf("%I64d
    ",maxx*(maxx-1)/2);//wa 4
        }
        return 0;
    }
  • 相关阅读:
    datetimepicker 日期值显示不完全(点击按钮后)
    南昌旋风科技有限公司的评价很烂,擅自修改dns域名解析。也不通知客户,导致34天无法解析。
    2009年树种铁树种子,每个特价3元一个!
    asp.net c# 如何读取XML文件里的CDATA里的HTML
    招商银行开始抢钱了,月管理费5元。2009年7月开始,杭州的招行是这样的。准备注销账号了
    圆通快递服务台太恶劣了,强烈要求抵制圆通快递。
    asp.net c#里如何使用 varchar(max) 参数
    MasterPage 和 page 事件顺序
    window7 安装 Microsoft SQL Server 2008 Enterprise Edition 需要注意的问题
    探讨下Tag标签的数据库设计(千万级数据量)
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3917900.html
Copyright © 2020-2023  润新知