Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

二分查找函数水过

Posted by 815536154 at 2016-08-13 10:17:03 on Problem 3663
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,s,tot;
int a[20005];
int main()
{
	cin>>n>>s;
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		int tmp=upper_bound(a+i,a+1+n,s-a[i])-a-1;
		if(tmp>i)
		tot+=tmp-i;
	}
	printf("%d\n",tot);
	return 0;
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator