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 |
呵呵,一下就a了,贴贴代码望大家指点指点#include <cstdio> #include <cstring> bool hash[2800]; int card[1000]; void Count_sort(int *arr,int arr_size) { int temp[100001]; memset(temp,0,sizeof(temp)); for (int i=0;i!=arr_size;++i) { ++temp[arr[i]]; } int j=0; for (int i=0;i!=100001;++i) { while(temp[i]!=0) { arr[j]=i; --temp[i]; ++j; } } } int main() { int m,n,c=1; while (scanf("%d%d",&m,&n)!=EOF) { if(m==0 && n==0)break; int ans=0; memset(hash,true,sizeof(hash)); for(int i=0;i!=n;++i) { scanf("%d",&card[i]); hash[card[i]]=false; } Count_sort(card,n); for(int i=n-1;i>=0;--i) { int j=card[i]+1; bool flag=0; while(j<=m*n) { if(hash[j]) { flag=1; hash[j]=false; break; } ++j; } if(!flag) { j=1; while(!hash[j])++j; hash[j]=false; ++ans; } } printf("Case %d: %d\n",c++,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