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

找不出那里错了,大家帮个忙吧

Posted by TN at 2005-01-31 13:19:37 on Problem 1042
#include <stdio.h>
#include <memory.h>
typedef struct mytype
{
    int id,num,d;
};
mytype a[26],heap[26];    
int t[26],way[26],best,ans[26];
int i,j,m,n,k,h,heaplen,tot,test;
void swap(mytype &a1,mytype &a2)
{
    mytype tmp;
    tmp=a1;a1=a2;a2=tmp;
}    
bool cmp(int s1,int s2)
{
    if (heap[s1].num>heap[s2].num || (heap[s1].num==heap[s2].num && heap[s1].id<heap[s2].id))
          return true;
    else
          return false;
}    
void adjust(int node)
{
    if (node*2<=heaplen)
      if (cmp(node*2,node))
        if (node*2+1<=heaplen && cmp(node*2+1,node*2))
        {
            swap(heap[node],heap[node*2+1]);
            adjust(node*2+1);
        }
        else
        {
            swap(heap[node],heap[node*2]);
            adjust(node*2);
        }
       else
        if (node*2+1<=heaplen && cmp(node*2+1,node))
        {
            swap(heap[node],heap[node*2+1]);
            adjust(node*2+1);
        }
}    
                       
int main()
{
    test=0;
    while ((scanf("%d",&n))!=EOF)
    {
        if (n==0) return 0;
        test++;
        scanf("%d",&h);
        h*=12;
        for (i=1;i<=n;i++) 
        {
            scanf("%d",&a[i].num);
            a[i].id=i;
        }
        for (i=1;i<=n;i++) scanf("%d",&a[i].d);
        for (i=1;i<n;i++) scanf("%d",&t[i]);t[0]=0;
        for (k=0;k<n;k++)
        {
            h=h-t[k];heaplen=k+1;
            for (i=1;i<=k+1;i++) heap[i]=a[i];
            for (i=heaplen/2;i>=1;i--) adjust(i);
            tot=0;memset (way,0,sizeof(way));
            for (i=1;i<=h;i++)
            {

                tot+=heap[1].num;
                heap[1].num-=heap[1].d;
                if (heap[1].num<0) heap[1].num=0;
                way[heap[1].id]++;
                adjust(1);
            }
            if (tot>=best) 
            {
                for (i=1;i<=n;i++) ans[i]=way[i];
                best=tot;
            }    
        }
        if (test!=1) printf("\n");
        printf("%d",ans[1]*5);
        for (i=2;i<=n;i++) printf(",%d",ans[i]*5);
        printf("\n");
        printf("Number of fish expected:%d\n",best); 
    }
}                
                
                 

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