• codeforces 459 B.Pashmak and Flowers 解题报告


    题目链接:http://codeforces.com/problemset/problem/459/B

    题目意思:有 n 朵 flowers,每朵flower有相应的 beauty,求出最大的beauty 差 和 要达到这个最大的差 的取法有多少种。

       一下子wa,是因为没考虑到整个序列都是相同的beauty 时的情况,以为取法是一种= =。注意,beauty 差为0都是合法的。还有注意这句话: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。 就是说,两种flower 只要有一种(当然两种也可以)和之前的取法不相同,就是一个新的取法。

        傻了,相同beauty > 2 时,答案应该是 n * (n-1) / 2!!!竟然写成 n * (n-1)了,这样会有重复取法数啦!!!!排列组合都还给老师了- -

         

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <algorithm>
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 const int maxn = 2e5 + 5;
    10 int b[maxn];
    11 
    12 int main()
    13 {
    14     int n;
    15     while (scanf("%d", &n) != EOF)
    16     {
    17         for (int i = 0; i < n; i++)
    18             scanf("%d", &b[i]);
    19         sort(b, b+n);
    20         int minn = b[0];
    21         int maxx = b[n-1];
    22         if (minn == maxx)
    23         {
    24             if (n == 2)
    25                 printf("0 1
    ");
    26             else
    27                 printf("0 %lld
    ", (LL)n * (LL)(n-1) / 2);
    28         }
    29         else
    30         {
    31             int cnt1 = 1;
    32             int cnt2 = 1;
    33             for (int i = 1; i < n; i++)
    34             {
    35                 if (minn == b[i])
    36                     cnt1++;
    37                 else
    38                     break;
    39             }
    40             for (int i = n-2; i >= 0; i--)
    41             {
    42                 if (maxx == b[i])
    43                     cnt2++;
    44                 else
    45                     break;
    46             }
    47             printf("%d %lld
    ", maxx-minn, (LL)cnt1*cnt2);
    48         }
    49     }
    50     return 0;
    51 }

         

  • 相关阅读:
    BootStrap .row-cols 类的用法
    苹果手机浏览器$(document).on(“click”,function(){})点击无效的问题
    $("节点名").html("字符串")和$("节点名").text("字符串")区别
    linux 安装Nginx
    linux安装nginx
    vue dev开发环境跨域和build生产环境跨域问题解决
    正在载入中......loading页面的几种方法
    浏览器断点调试js
    vue组件之间传值方式解析
    基于Vue + Vuex + Vue-router + Webpack 2.0打造微信界面
  • 原文地址:https://www.cnblogs.com/windysai/p/3916023.html
Copyright © 2020-2023  润新知