Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
题目链接:http://codeforces.com/problemset/problem/459/B
题意:
给出n支花,每支花都有一个漂亮值。挑选最大和最小漂亮值得两支花,问他们的差值为多少,并且有多少种选法(无先后顺序)。
现场做时,想到的是:用multimap记录每个漂亮值出现的次数,并不断更新最大最小值。
这个方法很笨,而且multimap的val值是多余的。
需要注意特殊情况:max==min
代码如下:
#include<iostream>//A - Pashmak and Flowers CodeForces - 459B
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map> using namespace std;
typedef long long ll; multimap<int,int> m; int main()
{
int n,max = -1,min = 2000000000,a;
ll smax,smin;
m.clear();
scanf("%d",&n);
for(int i = 0; i<n; i++)
{
scanf("%d",&a);
m.insert(pair<int,int>(a,0)); if(a>max) max = a;
if(a<min) min = a;
} smax = m.count(max);
smin = m.count(min); if(max==min)
printf("0 %lld\n",smax*(smax-1)/2);
else
printf("%d %lld\n",max-min, smax*smin); }
后来朋友说排序。恍然大悟,排个序什么都好说了。
代码如下:
#include<iostream>//A - Pashmak and Flowers CodeForces - 459B 排序
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm> using namespace std;
typedef long long ll; ll v[200005]; int main()
{
ll n,max,min,a,j,smax,smin,i; scanf("%lld",&n);
for(i = 0; i<n; i++)
{
scanf("%lld",&v[i]);
}
sort(v,v+n); min = v[0];
smin = 1;
for(i = 1; i<n && v[i]==min; i++)
smin++; max = v[n-1];
smax = 1;
for(i = n-2; i>=0 && v[i]==max; i--)
smax++; if(max==min)
printf("0 %lld\n",smax*(smax-1)/2);
else
printf("%lld %lld\n",max-min, smax*smin);
}
Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题的更多相关文章
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #290 (Div. 2) A. Fox And Snake 水题
A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...
- Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题
A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...
- Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...
- Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题
A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...
- Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida's problem(求逆序数对)
题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...
随机推荐
- 网站robots.txt探测工具Parsero
网站robots.txt探测工具Parsero robots.txt文件是网站根目录下的一个文本文件.robots.txt是搜索引擎中访问网站的时候要查看的第一个文件.当搜索引擎访问一个站点时,它 ...
- 【ZJOI2016】大♂森林
题目描述 小Y家里有一个大森林,里面有 $n$ 棵树,编号从 $1$ 到 $n$ .一开始这些树都只是树苗,只有一个节点,标号为 $1$ .这些树都有一个特殊的节点,我们称之为生长节点,这些节点有生长 ...
- 搭建高可用服务注册中心-Spring Cloud学习第一天(非原创)
文章大纲 一.Spring Cloud基础知识介绍二.创建单一的服务注册中心三.创建一个服务提供者四.搭建高可用服务注册中心五.项目源码与参考资料下载六.参考文章 一.Spring Cloud基础 ...
- erlang debugger
http://erlang.org/doc/apps/debugger/debugger_chapter.html
- Concurrency and Application Design (一)
在计算机发展的早期,单位工作时间的最高限额是一台计算机可以执行通过CPU的时钟速度确定.但是,随着技术的进步和处理器设计变得更紧凑,热等物理约束开始限制处理器的最高时钟速度.因此,芯片制造商寻找其它的 ...
- mac os安装jdk、卸载
1.JAVA版本8u171与8u172的区别 https://blog.csdn.net/u014653815/article/details/80435226 奇数版本是稳定版本,上面修订的所有 ...
- activiti自己定义流程之整合(二):使用angular js整合ueditor创建表单
基础环境搭建完成,接下来就该正式着手代码编写了,在说代码之前.我认为有必要先说明一下activit自己定义流程的操作. 抛开自己定义的表单不谈.通过之前的了解,我们知道一个新的流程開始.是在启动流程实 ...
- display:flex不兼容Android、Safari低版本的解决方案 【flex布局】
引自 http://www.cnblogs.com/shimily/articles/7943370.html <!DOCTYPE html> <html lang="en ...
- MySQL主从复制技术与读写分离技术amoeba应用
MySQL主从复制技术与读写分离技术amoeba应用 前言:眼下在搭建一个人才站点,估计流量会非常大,须要用到分布式数据库技术,MySQL的主从复制+读写分离技术.读写分离技术有官方的MySQL-pr ...
- Webduino Smart 从入门到起飞
前言 原创文章,转载引用务必注明链接.水平有限,如有疏漏,欢迎指正. 试用了一下,感觉这板子+WebduinoBlockly在线开发环境,下限低.上限也低,以后肯定要刷其他固件的.举个简单的例子,WB ...