| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
排了序不用二分也能过。。。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator