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 ...
随机推荐
- JVM, JRE 和JDK
JVM -- java virtual machine A Java virtual machine (JVM) is a process virtual machine that can execu ...
- JD静态网页
1.制作导航栏 ul>li*n>a 2.制作竖线 a.利用border b.利用 | c.利用矩形,宽度设为1,设置背景色,padding = 0 3.制作下三角 (1)◇ (2)两个盒 ...
- IntelliJ IDEA导入包的顺序调整和按包类型分类(保持和Eclipse一致)
调整的内容如下: 空行 import java.* 空行 import javax.* 空行 import com.* 空行 import all other imports 空行 import st ...
- 【IntelliJ idea/My/ecplise】启动项目前,修改配置JVM参数
My/ecplise下都是一样的: IDEA下:
- 【Todo】Java并发学习 & 示例练习及代码
接上一篇:http://www.cnblogs.com/charlesblc/p/6097111.html <Java并发学习 & Executor学习 & 异常逃逸 & ...
- HDU 4403 A very hard Aoshu problem (DFS暴力)
题意:给你一个数字字符串.问在字符串中间加'='.'+'使得'='左右两边相等. 1212 : 1+2=1+2, 12=12. 12345666 : 12+3+45+6=66. 1+2+3+4 ...
- 百度 BAE 项目部署
转载:http://www.cnblogs.com/shamoyuu/p/node_bae.html 百度有一个应用引擎,价格非常便宜,Java的tomcat每天4毛钱,node每天2毛钱,我以前在上 ...
- vue2.0 自定义 生成二维码(QRCode)组件
1.自定义 生成二维码组件 QRCode.vue <!-- 生成二维码 组件 --> <template> <canvas class="qrcode-canv ...
- vue2.0 + vux (六)NewsList 资讯页 及 NewsDetail 资讯详情页
设置代理,避免出现跨域问题 /*设置代理,避免出现跨域问题*/ proxyTable: { '/api':{ target: 'https://www.oschina.net/action/apiv2 ...
- H2数据库集群
H2数据库集群 1. H2数据库简单介绍 1.1 H2数据库优势 经常使用的开源数据库:H2,Derby,HSQLDB.MySQL,PostgreSQL. 当中H2,HSQLDB相似,十分适合作为嵌入 ...