Codeforces #261 Div 2 B
来源:互联网 发布:windows快捷键设置 编辑:程序博客网 时间:2024/06/06 00:09
题目大意:
给定一段序列,求出的序列的最大差值和组成这段差值的组合数量。
题目分析:
想想自己真的是缺少比赛的经验,神奇地ce了几次,想到大致算法却忽略了小细节。
这道题其实很好,考验对数据的处理,首先是排序,然后分类讨论
1、* 如果数据全都相同,那么就考虑N个数相互组合的可能数量。即n*(n-1)/2
2 、 否则的话直接乘法原理。
还有一个问题就是,数据的大小。
N的数量是2*10^5级的,相乘的话可能爆int,所以要注意long long'
如下代码:
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;int n;int a[200010];int main(){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);long long s1=upper_bound(a+1,a+n+1,a[1])-lower_bound(a+1,a+n+1,a[1]);long long s2=upper_bound(a+1,a+n+1,a[n])-lower_bound(a+1,a+n+1,a[n]);if(a[n]!=a[1])printf("%d %lld\n",a[n]-a[1],s1*s2);else printf("%d %lld\n",a[n]-a[1],(long long )(n-1)*n/2);//while(1);return 0;}
0 0
- Codeforces #261 Div 2 B
- Codeforces Round #261 (Div. 2) B
- codeforces #368 div.2B
- Codeforces--477Div.2--B
- Codeforces Round #261 (Div. 2)B. Pashmak and Flowers
- Codeforces #261 (Div. 2)B. Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B.Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers【水】
- Codeforces Round #261 (Div. 2) A,B,C,D,E
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers
- Codeforces Round #261 (Div. 2)B. Pashmak and Flowers
- Codeforces Round #261 (Div. 2) B. Pashmak and Flowers 水题
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Round #181 (Div. 2) B. Coach
- Codeforces Round #185 (Div. 2)--A,B
- 十种免费的项目管理工具
- BNUOJ 34490 Justice String,字符串哈希,二分
- Python 3语法小记 类class
- Spring : 征服数据库(一)
- 概念的讨论
- Codeforces #261 Div 2 B
- 第一章:操作系统概述
- IOS-UIImageView 图片自适应大小
- 高等数学(上)期末考试试题(A)——卷一
- Wifi的密码长度有何限制
- Lua学习笔记 第十五章 模块与包
- LeetCode 19 Clone Graph
- 如何量化评价搜索引擎的结果质量
- IOS:修改NavigationController的后退按钮标题