Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哪位帮我看看代码,或者给个数据也好啊#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator