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 lijiaming12340 at 2013-10-28 17:43:29 on Problem 3663
#include<stdio.h>
int a[1000001];
int main()
{
 long int l[20001],i,j,k,n,s,max=0,ans=0;
 memset(a,0,sizeof(a));
 scanf("%d %d",&n,&s);
 for (i=1; i<=n; i++)
 {
  scanf("%d",&l[i]);
  a[l[i]]++;
  if (l[i]>max) max=l[i];
 }
 for (i=1; i<=s; i++) a[i]+=a[i-1];
 for (i=1; i<=n; i++)  
     if (l[i]<s) 
	 {
	  ans+=a[s-l[i]];
	  if (s-l[i]>=l[i]) ans--;
	 }
 printf("%d",ans/2);
 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