排序后遍历,每个元素向后找m以内差距的元素个数乘二求和
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <cmath> #include <cstdio> #include <string> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int hgt[1001]; int main() { int n,m,cnt,ans=0; cin>>n>>m; memset(hgt,0,sizeof hgt); for(int i=0;i<n;i++) { cin>>hgt[i]; } sort(hgt,hgt+n); for(int i=0;i<n;i++) { cnt=0; for(int j=i+1; hgt[j]<=hgt[i]+m && j<n; j++ ) { cnt++; } ans+= 2*cnt; } printf("%d",ans); return 0; }
最后
以上就是时尚太阳最近收集整理的关于【水排序】#32 A. Reconnaissance的全部内容,更多相关【水排序】#32内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复