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)了,这样会有重复取法数啦!!!!排列组合都还给老师了- -
#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 解题报告的更多相关文章
- codeforces 459 A. Pashmak and Garden 解题报告
题目链接:http://codeforces.com/problemset/problem/459/A 题目意思:给出两个点的坐标你,问能否判断是一个正方形,能则输出剩下两点的坐标,不能就输出 -1. ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- codeforces 474D.Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/474/D 题目意思:Marmot 吃两种类型的花(实在难以置信呀--):red 或者 white,如果要吃 ...
- codeforces B. Ciel and Flowers 解题报告
题目链接:http://codeforces.com/problemset/problem/322/B 题目意思:给定红花.绿花和蓝花的朵数,问组成四种花束(3朵红花,3朵绿花,3朵蓝花,1朵红花+1 ...
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
- codeforces 433C. Ryouko's Memory Note 解题报告
题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...
- codeforces 459 E. Pashmak and Graph(dp)
题目链接:http://codeforces.com/contest/459/problem/E 题意:给出m条边n个点每条边都有权值问如果两边能够相连的条件是边权值是严格递增的话,最长能接几条边. ...
- 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, ...
随机推荐
- CodeForces 379D 暴力 枚举
D. New Year Letter time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- iOS APP 架构漫谈[转]
Mark 一下 很不错的文章 最近看了一些有关server的东西,一些很简单的东西,不外乎是一些文档规范,另外结合最近看的wwdc的一些video,觉得对软件架构(software arch ...
- Android借助Handler,实现ViewPager中页面的自动切换(转)
在很多电商网页及app上都有自动切换的商品的推广快,感觉体验挺不错的,正好今天学习使用ViewPager,因此也实现了一个功能类似的demo. 下面是其中的两个截图: 实现一个自动 ...
- STM32调试问题
1.JLINK V8 error:flash download failed - could not load file: Options for Target 'Targer 1'下的菜单下Outp ...
- stm32的IIc总线--超声波测距
- java通过反射获取bean字段注解@Column中的信息
直接上代码吧: Field field; Field[] fields=clas.getDeclaredFields(); for (int i = 0; i <fields.length ; ...
- [转] windows下Svn服务器之必须提交修改注释篇
1. 强制添加注释信息 找到Respositories目录下对应项目里的hooks目录下建立pre-commit.bat文件,复制如下内容: @echo off set SVNLOOK="C ...
- Linux之时钟中断
from:深入分析Linux内核源码(http://oss.org.cn/kernel-book/) 时钟中断的产生 Linux的OS时钟的物理产生原因是可编程定时/计数器产生的输出脉冲,这个脉冲送入 ...
- expect实现无交互操作
按两下tab linux总共2000个命令,,常用的200个命令. 只要文件改变了,MD5值就会变!
- 创建es索引-格式化和非格式化
创建es索引-格式化和非格式化 学习了:https://www.imooc.com/video/15768 索引有结构化和非结构化的区分: 1, 先创建索引,然后POST修改mapping 首先创建索 ...