现在的位置: 首页 > 综合 > 正文

【BZOJ】【P2348】【Baltic 2011】【Plagiarism】【二分】

2017年04月18日 ⁄ 综合 ⁄ 共 369字 ⁄ 字号 评论关闭

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2348

水题不解释

Code:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	long long ans=0;
	for(int i=1;i<=n;i++){
		int l=1,r=i;
		while(l<r){
			int mid=(l+r)>>1;
			if(a[mid]*10>=a[i]*9)
				r=mid;
			else l=mid+1;
		}ans+=i-l;
	}cout<<ans<<endl;
	return 0;
}

抱歉!评论已关闭.