题目链接: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 水题的更多相关文章

  1. 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 ...

  2. 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  ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #261 (Div. 2)459D. Pashmak and Parmida&#39;s problem(求逆序数对)

    题目链接:http://codeforces.com/contest/459/problem/D D. Pashmak and Parmida's problem time limit per tes ...

随机推荐

  1. Java heap space设置方法记录

    最近被 OutOfMemory Error折腾得够呛,记载一点设置JVM虚拟机内存Javaheap space的方法. Tomcat 7 参考:  http://www.davidghedini.co ...

  2. java计算年龄

    精确到天计算年龄 public static int getAgeByCardId(String card) throws Exception { Integer len = card.length( ...

  3. 四个很好的开源app项目

    Open Source and the iOS App Store Today, we are open-sourcing 4 iOS apps: ThatInbox, an email client ...

  4. scala工具sbt的安装和使用;idea如何创建scala项目

    scala的sbt类似于java的maven mac:brew install sbt linux:yum Install sbt 或者下载二机制包 使用sbt需要想mvn一样搭建公司私服,不然,下载 ...

  5. SilverLight:基础控件使用(3)-DataGrid控件

    ylbtech-SilverLight-Basic-Control:基础控件使用(3)-DataGrid控件 DataGrid控件-后台绑定 自动生成表列 不自动生成表列 1.A,返回顶部Person ...

  6. mysql_config_editor使用简介

      原文 : http://blog.itpub.net/29773961/viewspace-1817640/   ----------------------------------------- ...

  7. serialVersionUID的作用以及如何用idea自动生成实体类的serialVersionUID

    转载:http://blog.csdn.net/liuzongl2012/article/details/45168585 serialVersionUID的作用: 通过判断实体类的serialVer ...

  8. C#中toolStrip或statusStrip遮挡了SplitContainer怎么办?

    如果在一个项目中先增添了SplitContainer,然后再添加的Toolbar或statusStrip,结果后者把前者上部或下部挡住了一条,造成界面别扭. 解决办法是右键点击Toolba或statu ...

  9. 安装mongoDB遇见的一个路径问题

    如果安装路径不存在,则不会解压EXE软件! 安装monogoDB后,它不会自动添加执行路径! 意思就是安装路径是D盘下面的mongoDB文件夹,假如不存在这个文件夹,则不会安装成功 你需要添加路径: ...

  10. C++学习总结1

    一.内存管理 一般new 与 delete 同时出现.假如释放一个对象用 delete p即可.多个对象用delet [ ]p  即:new与delete需要搭配好. C++继承了C的许多函数,mal ...