hdu 4422

#include<stdio.h>
#include<string.h>
#define inf  0x7fffffff
int main() {
    int i,j,k,a[6],n;
    while(scanf("%d",&n)!=EOF) {
        memset(a,0,sizeof(a));

        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        if(n<=3) {
            printf("1024\n");
            continue;
        }
        if(n==4) {
            int sum=0,max=0;
            for(i=0;i<n;i++)
                for(j=i+1;j<n;j++) {
                    sum=a[i]+a[j];
                    if(sum==0)
                        sum=0;
                    else
                    if(sum%1024==0)
                        sum=1024;
                    else
                        sum=sum%1024;
                    if(sum>max)
                        max=sum;
                }
                    for(i=0;i<n;i++)
                        for(j=i+1;j<n;j++)
                            for(k=j+1;k<n;k++)
                                if((a[i]+a[j]+a[k])%1024==0)
                                    max=1024;
                                printf("%d\n",max);
                                continue;
                }
        int mx=0,my=1,mz=2,max=inf;
        for(i=0;i<n;i++)
            for(j=i+1;j<n;j++)
                for(k=j+1;k<n;k++)
                    if((a[i]+a[j]+a[k])%1024==0&&a[i]+a[j]+a[k]<max) {
                        max=a[i]+a[j]+a[k];
                        mx=i;my=j;mz=k;
                    }
                    if(max==inf) {
                        printf("0\n");
                        continue;
                    }
                     int sum=0;
                    for(i=0;i<5;i++)
                        if(i!=mx&&i!=my&&i!=mz)
                            sum+=a[i];
                        if(sum==0)
                            sum=0;
                        else
                        if(sum%1024==0)
                            sum=1024;
                        else
                        sum=sum%1024;
                        printf("%d\n",sum);
    }
    return 0;
}//一个很好的博客地址解释http://blog.csdn.net/u011519618/article/details/9883465

posted @ 2013-08-12 15:59  HYDhyd  阅读(193)  评论(0编辑  收藏  举报