题目链接: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)了,这样会有重复取法数啦!!!!排列组合都还给老师了- -

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long LL;
const int maxn = 2e5 + ;
int b[maxn]; int main()
{
int n;
while (scanf("%d", &n) != EOF)
{
for (int i = ; i < n; i++)
scanf("%d", &b[i]);
sort(b, b+n);
int minn = b[];
int maxx = b[n-];
if (minn == maxx)
{
if (n == )
printf("0 1\n");
else
printf("0 %lld\n", (LL)n * (LL)(n-) / );
}
else
{
int cnt1 = ;
int cnt2 = ;
for (int i = ; i < n; i++)
{
if (minn == b[i])
cnt1++;
else
break;
}
for (int i = n-; i >= ; i--)
{
if (maxx == b[i])
cnt2++;
else
break;
}
printf("%d %lld\n", maxx-minn, (LL)cnt1*cnt2);
}
}
return ;
}

codeforces 459 B.Pashmak and Flowers 解题报告的更多相关文章

  1. codeforces 459 A. Pashmak and Garden 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...

  2. codeforces 459C Pashmak and Buses 解题报告

    题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...

  3. codeforces 474D.Flowers 解题报告

    题目链接:http://codeforces.com/problemset/problem/474/D 题目意思:Marmot 吃两种类型的花(实在难以置信呀--):red 或者 white,如果要吃 ...

  4. codeforces B. Ciel and Flowers 解题报告

    题目链接:http://codeforces.com/problemset/problem/322/B 题目意思:给定红花.绿花和蓝花的朵数,问组成四种花束(3朵红花,3朵绿花,3朵蓝花,1朵红花+1 ...

  5. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  6. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  7. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  8. codeforces 459 E. Pashmak and Graph(dp)

    题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. ...

  9. codeforces 459 D. Pashmak and Parmida's problem(思维+线段树)

    题目链接:http://codeforces.com/contest/459/problem/D 题意:给出数组a,定义f(l,r,x)为a[]的下标l到r之间,等于x的元素数.i和j符合f(1,i, ...

随机推荐

  1. Windows下ElasticSearch的使用方式 CURL+Cygwin+Head插件

    Windows使用ElasticSearch的命令方法 一.CURL(不推荐) 下载curl安装包,解压到指定目录,在命令行运行解压后的exe文件. 二.Cygwin(推荐) 安装Windows下类l ...

  2. Virtualization基础

    官方文档学习 https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/pdf/Virtualization_G ...

  3. Jsp中路径问题

    ${pageContext.request.contextPath}”的作用是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的. <!--使用绝对路径的方式引入CSS文件-->& ...

  4. KJ面试

    1.css input checkbox和radio样式美化 <span class="pay_list_c1 on"> <input type="ra ...

  5. android的对话框

    android中的对话框形式有四种,分别是一般对话框形式,列表对话框形式,单选按钮对话框,多选按钮对话框,下面我一一对他们进行详解. <一>一般对话框 一般对话框形式如下图: 具体实现代码 ...

  6. 模拟用户登录-SpringMVC+Spring+Mybatis整合小案例

    1. 导入相关jar包 ant-1.9.6.jarant-launcher-1.9.6.jaraopalliance.jarasm-5.1.jarasm-5.2.jaraspectj-weaver.j ...

  7. ROS下使用ASUS Xtion Pro Live

    一.ROS官网hydro版本OpenNI安装 3. Installation 3.1 Ubuntu installation To install only openni_camera: sudo a ...

  8. Maven使用site-deploy(site:deploy)部署通过site生成的文档(Tomcat-WebDAV)

    Maven可以通过site生成项目的帮助文档,并且格式为html,那么可以通过site-deploy把文档部署到远端,部署方式支持HTTP/FTP/SCM/WebDAV等. 更多部署方案,参考:htt ...

  9. 【SQL Server 学习系列】-- 获取字符串中出现某字符的次数及字符某次出现的下标

    ) = '1_BB_CC_DD_AA_EE_YY_WW_HH_GG' --// 1. 获取下划线在字符串中出现的次数 SELECT LEN(@Str) - LEN(REPLACE(@Str, '_', ...

  10. NSURLConnection和NSMutableURLRequest 实现同步、异步请求

    我是走向ios的一个小书童,我有很多不懂的,新鲜的知识去学习,去掌握! 我首先要吐槽一下: 那些不负责的博友!你分享知识本来是好事!可是你直接Control+V就是你的不对了! 尼玛,直接Contro ...