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 |
关于题目某些数据的范围客户要求的邮票总值范围是<=62的,每张邮票的面值<=3,本人二分测的,测试程序如下,如有任何疑问,请保留··· #include<cstdio> #include<algorithm> #include<string> #include<iostream> #include<cmath> #include<vector> #include<fstream> #include<map> #include<queue> using namespace std; int ans[63][8],p[25],a[4],n; char h[4]; void orz(int sum,int index,int pre,int cnt,int dcnt) { if(index>=n) return; orz(sum,index+1,pre,cnt,dcnt); if(index!=pre) {dcnt++; pre=index;} a[cnt]=p[index]; cnt++; sum+=p[index]; if(dcnt==ans[sum][0]&&cnt==ans[sum][1]&&p[index]==ans[sum][2]) ans[sum][3]=1; else if(dcnt>ans[sum][0]||dcnt==ans[sum][0]&&cnt<ans[sum][1]||dcnt==ans[sum][0]&&cnt==ans[sum][1]&&p[index]>ans[sum][2]) { ans[sum][0]=dcnt; ans[sum][1]=cnt; ans[sum][2]=p[index]; ans[sum][3]=0; for(int i=4;i<4+cnt;i++) ans[sum][i]=a[i-4]; } if(cnt!=4) orz(sum,index,pre,cnt,dcnt); } int main() { int tmp; while(scanf("%d",&tmp)!=EOF) { n=0; memset(h,0,sizeof(h)); for(int i=0;i<63;i++) ans[i][0]=-1; do { if(tmp==0) break; if(h[tmp]<5) {p[n++]=tmp; h[tmp]++;} }while(scanf("%d",&tmp)!=EOF); sort(p,p+n); orz(0,0,-1,0,0); while(scanf("%d",&tmp)&&tmp) { if(ans[tmp][0]==-1) printf("%d ---- none\n",tmp); else if(ans[tmp][3]) printf("%d (%d): tie\n",tmp,ans[tmp][0]); else { printf("%d (%d):",tmp,ans[tmp][0]); for(int i=0;i<ans[tmp][1];i++) printf(" %d",ans[tmp][4+i]); putchar('\n'); } } } }; Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator