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 radish at 2007-07-23 11:07:51 on Problem 3273
#include <iostream>
using namespace std;
int check(int Days[], int mid, int N, int M)
{
    int Di, Mi, Month;
    for ( Month = Di = Mi = 0; Di < N && Mi < M; )
    {
        if ( Month + Days[Di] <= mid )
        {
            Month += Days[Di++];
        }
        else
        {
            Month = Days[Di++];
            ++Mi;
        }
    }
    if ( Di == N && Mi + 1 == M )
    {
        return 0;
    }
    else if (Di == N && Mi < M )
    {
        return 1;
    }
    else 
    {
        return 2;
    }
}
int main()
{
    int N, M, Di, k, min = 1, max = 10000, mid;
    cin >> N >> M;
    int Days[N];
    for ( Di = 0; Di < N; ++Di )
    {
        scanf("%d", &Days[Di]);
        if ( min < Days[Di] )
        {
            min = Days[Di];
        }
    }
    while ( min + 1 < max )
    {
        mid = (min + max) / 2;
        k = check(Days, mid, N, M);
        if ( k <= 1 )
        {
            max = mid;
        }
        else 
        {
            min = mid;
        }
    }
    if ( check(Days, min, N, M) == 0 )
    {
        cout << min << endl;
    }
    else
    {
        cout << max << endl;
    }
    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