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,用正确代码测试也没有发现错误!哪位帮忙看看!给些测试数据也行呀!

Posted by cy_forever at 2008-08-21 10:59:11 on Problem 1042 and last updated at 2008-08-21 14:29:36
#include<iostream>
using namespace std;
int main()
{
    int h,n,fi[25],di[25],ti[25],leave[25],total;
    int tempfi[25],temptotal,use[25],temptime,i,j,k,f,top,pos;
    cin>>n;
    while (n)
    {
        cin>>h;
        h *= 60;
        total = f = 0;
        memset(leave, 0, sizeof(leave));
        memset(fi, 0, sizeof(fi));
        memset(di, 0, sizeof(di));
        memset(ti, 0, sizeof(ti));
        for (i=0; i<n; i++)
        {
            cin>>fi[i];
            f += fi[i];
        }
        for (i=0; i<n; i++)
        {
            cin>>di[i];
        }
        ti[0] = 0;
        for (i=1; i<n; i++)
        {
            cin>>ti[i];
            ti[i] += ti[0];
            ti[0] = ti[i];
        }
        ti[0] = 0;
        if (!f)
        {
            leave[0] = h;
            for (i=0; i<n-1; i++)
            {
                cout<<leave[i]<<", ";
            }
            cout<<leave[n-1]<<"\nNumber of fish expected: "<<0<<endl<<endl;
            cin>>n;
            continue;
        }
        for (i=0; i<n; i++)
        {
            memcpy(tempfi, fi, sizeof(fi));
            memset(use, 0, sizeof(use));
            temptotal = 0;
            temptime = h-ti[i]*5;
            for (j=0; j<temptime/5; j++)
            {
                top = tempfi[0];
                pos = 0;
                for (k=1; k<=i; k++)
                {
                    if (tempfi[k]>top)
                    {
                        pos = k;
                        top = tempfi[k];
                    }
                }
                if (top==0)
                {
                    use[0] += (temptime-j*5); 
                    break;
                }
                temptotal += top;
                tempfi[pos] -= di[pos];
                if (tempfi[pos] < 0)
                {
                    tempfi[pos] = 0;
                }
                top = tempfi[pos];
                use[pos] += 5;
            }
            if (total<temptotal)
            {
                total=temptotal;
                memcpy(leave, use, sizeof(use));
            }
        }
        for (i=0; i<n-1; i++)
        {
            cout<<leave[i]<<", ";
        }
        cout<<leave[n-1]<<"\nNumber of fish expected: "<<total<<endl<<endl;
        cin>>n;
    }
    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