Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

脑袋快暴了,求大家帮我看一下吧,WA的次数我已经数不过来了,算法我也想不出错误。真FAINT死了快。。。。

Posted by shan11 at 2006-08-22 20:38:19 on Problem 1015
给我找个错误数据也好,我真是没办法了实在是。。。。
#include<stdio.h>
#include<stdlib.h>

#define MAX 1001

typedef struct{
    int sum;
    int dif;//d-p
}candidate;

typedef struct{
    int x[210];//member 
    int exist;//exist or not 
    int total;//sum of d and p
}ele;

candidate C[210];//candidates
ele*a;//rotating array a and b
ele*b;

int main(){
    int m;
    int n;
    int d;
    int p;
    int i;
    int j;
    int t;
    int max;
    int l;
    int pos;
    int k;
    ele* temp;
    
    a=(ele*)malloc(MAX*sizeof(ele));
    b=(ele*)malloc(MAX*sizeof(ele));
    
    scanf("%d %d",&n,&m);
    k=1;
    while(n||m){
        for(i=0;i<n;i++){
            scanf("%d %d",&p,&d);
            C[i].sum=d+p;
            C[i].dif=d-p;
        }
        
        for(i=0;i<=1000;i++){ //i+500 is the real dif
            if(i==500){
                a[i].exist=1;
                for(j=0;j<210;j++)a[i].x[j]=0;
                a[i].total=0;
            }
            else a[i].exist=0;
        }
          
        for(i=1;i<=m;i++){
           for(j=0;j<=1000;j++){ //j-500 is the real d(J)-d(p) 
               max=-1;
               pos=-1;
               for(t=0;t<n;t++)
                   if(j-C[t].dif>=0&&j-C[t].dif<=1000)
                       if(a[j-C[t].dif].exist&&!a[j-C[t].dif].x[t]){
                           b[j].exist=1;
                           if(max<=C[t].sum+a[j-C[t].dif].total){
                               max=C[t].sum+a[j-C[t].dif].total;
                               pos=t;
                           }
                       }
               if(max==-1)b[j].exist=0;
               else {
                   for(l=0;l<n;l++)b[j].x[l]=a[j-C[pos].dif].x[l];
                       b[j].x[pos]=1;
                       b[j].total=max;
               }
           }    
           temp=a;
           a=b;
           b=temp;        
        }
        max=10000000;
        p=0;
        d=0;
        printf("Jury #%d\n",k);
        for(i=0;i<MAX;i++)
            if(a[i].exist){
                if((i-500)<0){
                    if(max>500-i){
                        max=500-i;
                        pos=i;
                    }
                }
                else if(max>i-500){
                    max=i-500;
                    pos=i;
                }
            }            
        for(i=0;i<n;i++)
            if(a[pos].x[i]){
                d+=(C[i].sum+C[i].dif)/2;
                p+=(C[i].sum-C[i].dif)/2; 
            }
        printf("Best jury has value %d for prosecution and value %d for defence:\n",p,d);
        for(i=0;i<n;i++)
            if(a[pos].x[i])printf(" %d",i+1);      
        printf("\n\n");
        scanf("%d %d",&n,&m);
        k++;
    }
    system("PAUSE");
    return 0;
}
        
                          
                       
            
               
        
    

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator