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 a470086609 at 2009-06-09 11:02:12 on Problem 3663
In Reply To:先排序,再二分,注意有长度相等的情况。什么也不多说了,贴。。。 Posted by:bjtu1 at 2009-04-07 23:03:33
int n,s;
int a[20010];

int main()
{
	int i,j;
	int num=0;
	scanf("%d%d",&n,&s);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);

    
	for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]+a[j]<=s)
                num++;
            else
                break;
        }
    }
    printf("%d\n",num);
	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