题目链接: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. 更全的bootstrap教程连接

    更全的bootstrap教程: http://www.jb51.net/article/84087.htm

  2. Codeforces Round #265 (Div. 2) C 暴力+ 找规律+ 贪心

    C. No to Palindromes! time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. hdu - 2667 Proving Equivalences(强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=2767 求至少添加多少条边才能变成强连通分量.统计入度为0的点和出度为0的点,取最大值即可. #include & ...

  4. 阻塞IO下的echo回显实验

    我们只关心代码中的业务逻辑和底层阻塞原因 客户端代码 发送数据 std::string message(len, 'S'); int nw = stream->sendAll(message.c ...

  5. 2017 ACM/ICPC Asia Regional Xian Online 记录

    题目链接  Xian

  6. ueditor整合之后前段不显示高亮

    自己整合ueditor插件后,发现在前段显示的时候并没有高亮处理 在网上看了一些方法后,自己尝试了下. 1.在页面上引入相关的js和css文件 主要是以下两个文件 <script src=&qu ...

  7. Dfs学习经验(纸上运行理解DFS)【两道题】

    首先我想吐槽的是,在CSDN上搞了好久还是不能发博客,就是点下发表丝毫反应都没有的,我稍微百度了几次还是没有找到解决方法,在CSDN的BBS上也求助过管理员但是没有收到答复真是烦躁,导致我新生入学以来 ...

  8. yum gd linux

    32位操作系统安装命令:[root@localhost ~]# yum install php-gd*64位操作系统安装命令:[root@localhost ~]# yum install php-g ...

  9. 通过Python实现自动填写调查问卷

    0X00 前言 快开学了,看到空间里面各种求填写调查问卷的,我才想起来貌似我也还没做.对于这种无意义的问卷,我是不怎么感冒的,所以我打算使用”特技”来完成,也就是python,顺便重新复习一下pyth ...

  10. Git checkout on a remote branch does not work

    I believe this occurs when you are trying to checkout a remote branch that your local git repo is no ...