zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    堆排序实现
    Unable to convert MySQL date/time value to System.DateTime
    想想那些除了技术之外重要的事情
    js小功能
    01输入框回车触发操作
    javascript闭包
    BQ27510 电量计的校准 的 C语言实现
    嵌入式Linux开发教程:Linux常见命令(上篇)
    技术团队的情绪与效率
    如何有效使用Project(2)——进度计划的执行与监控
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3917900.html
Copyright © 2011-2022 走看看