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:yiyiyi4321 at 2006-03-25 21:25:08 > #include<stdio.h> > > long used[10001]; > > int main() > { > long i,j,n,ans; > int bin,m; > > scanf("%ld",&n); > memset(used,0,sizeof(used)); > for(i=0;i<n;i++) > { > scanf("%d",&m); > used[m]++; > } > ans=0; > ans+=used[bin]; > for(i=bin-1;i>=0;i--) > { > while(used[i]) > { > used[i]--; > ans++; > for(j=bin-i>i?i:bin-i;j>=0;j--) > if(used[j])break; > if(j>=0)used[j]--; > } > } > printf("%ld\n",ans); > > return 0; > } > Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator