http://codeforces.com/problemset/problem/158/B
贪心:4人1车,(3+1)人1车,(2+2)人1车,(2+1+1)人1车,(1*4)人1车
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; int a[5]; int main() { // freopen("1.txt","r",stdin); int i,n,x,sum; while(~scanf("%d",&n)) { memset(a,0,sizeof(a)); sum=0; for(i=0; i<n; i++) { cin>>x; a[x]++; } sum+=a[4]+a[3]; x=a[1]-a[3]; if(a[2]%2==0) sum+=a[2]/2; else { sum+=(a[2]+1)/2; x-=2; } if(x>0) { sum+=x/4; x=x%4; if(x) sum++; } cout<<sum<<endl; } return 0; }