题目链接: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. man

    Description n间房子高度不同,Man 要从最矮的房子按照高度顺序跳到最高的房子,你知道房子的顺序,以及Man一次最远可以跳多远,相邻的房子至少有1的距离,房子的宽不计,现在由你安排相邻房子 ...

  2. SQL SERVER 工具

    http://www.cnblogs.com/fygh/archive/2012/04/25/2469563.html

  3. ios使用http来上传图片实现方法

    if (parameters) {                int genderNumber = 1;        self.token = loginToken;        self.p ...

  4. 记Weblogic采用RAC方式链接数据库遇到的问题

      前几天,去客户现场部署系统,WEBLOGIC连接数据库使用RAC方式连接,好几个人弄了一下午愣是没搞定,总是报SID错误 开始一致认为是防火墙的原因,后来SSH登陆应用服务器后,再TELNET数据 ...

  5. iOS -- YYText富文本

    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: [NSString strin ...

  6. 基于HTML5的PACS--HTML5图像处理

    在此之前,此系统是结合DICOM的WADO标准,在浏览器里通过javascript操作返回的JPG图片.这种服务器端解析,客户端展现的方式,对实现图像的移动.缩放.旋转.测量等图像操作能够实现实时的交 ...

  7. [c++菜鸟]《Accelerate C++》习题解答

    第0章 0-0 编译并运行Hello, world! 程序. #include <iostream> using namespace std; int main() { cout < ...

  8. HDU 2648(搜索题,哈希表)

    #include<iostream> #include<map> #include<string> #include<cstring> #include ...

  9. Google Chrome浏览器之删除Goolge搜索结果重定向插件Remove Google Redirects

    https://chrome.google.com/webstore/detail/remove-google-redirects/ccenmflbeofaceccfhhggbagkblihpoh?h ...

  10. iOS 插件制作

    概述 我们平时也使用了非常多的xcode插件,尽管官方对于插件制作没有提供不论什么支持,可是载入三方的插件,默认还是被同意的.第三方的插件,须要存放在 ~/Library/Application Su ...