题目链接: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. 16.1113 模拟考试T1

    笔记[问题描述]给定一个长度为m的序列a,下标编号为1~m.序列的每个元素都是1~N的整数.定义序列的代价为累加(1->m-1 abs(ai+1-ai))你现在可以选择两个数x和y,并将序列?中 ...

  2. msp430项目编程45

    msp430综合项目---蓝牙控制系统45 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结

  3. shell的select脚本的简单入门

    shell的select脚本的简单入门 语法:select var in ...;do break;doneecho $var 示例: #/bin/bash echo "what is yo ...

  4. css3 nth-child 与 nth-of-type 的区别

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1709 一.深呼吸,直 ...

  5. eclipse 安卓虚拟机安装apk 及常见问题

    首先必须启动虚拟机然后如图操作:

  6. jpaRepository findById()数据库有数据却为null

    oracle中的char类型用空格自动将字段补成指定的长度, 而varchar2类型不会.大部分情况下设计表字段类型都是varchar2,今天被char坑了一次, findById()始终为空..

  7. mysql中进行删除操作时用到not in 导致删除不成功

    delete from tb_news where id not in ( select max(id) From tb_news Group By title ) 刚开始用这条语句删除一直不成功 然 ...

  8. 5.Longest Palindrome substring

    /* * 5.Longest Palindrome substring * 2016-4-9 by Mingyang 自然而然的想到用dp来做 * 刚开始自己做的时候分的条件太细,两个index相等, ...

  9. phpQuery用法总结

    项目下载地址:http://code.google.com/p/phpquery/ 获取内容的方法: 第一种:newDocumentFile phpQuery::newDocumentFile($ur ...

  10. flask的debug模式下,网页输入pin码进行调试

    网站后端Python+Flask .FLASK调试模式之开启DEBUG与PIN使用? 自动加载: # 方式一 1 2 if __name__ == '__main__':     app.run(ho ...