poj 1042 贪心

来源:互联网 发布:淘宝网天猫大码女装 编辑:程序博客网 时间:2024/05/22 22:17

题解见我的另一篇文章点击打开链接

这提要注意的是有些湖是到不了的

一组数据:

310 76 500 30 720 13ans:60, 0, 0Number of fish expected: 0
AC代码如下:

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <queue>using namespace std;int main(){int N, H;int f[30], d[30], t[30];while( cin >> N && N ){cin >> H;for( int i = 1; i <= N; i++ ){cin >> f[i];}for( int i = 1; i <= N; i++ ){cin >> d[i];}for( int i = 1; i < N; i++ ){cin >> t[i];}int fishtimes, ans_times[30], max_ans = -1;memset( ans_times, 0, sizeof( ans_times ) );for( int i = 1; i <= N; i++ ){int temp = 0;for( int j = 1; j < i; j++ ){temp += t[j] * 5;}fishtimes = ( H * 60 - temp ) / 5;if( fishtimes < 0 ){                break;}int temp_f[30], temp_ans_times[30], temp_max_ans = 0;memset( temp_ans_times, 0, sizeof( temp_ans_times ) );for( int j = 1; j <= i; j++ )temp_f[j] = f[j];for( int j = 1; j <= fishtimes; j++ ){int tp = 1;for( int k = 1; k <= i; k++ ){if( temp_f[k] > temp_f[tp] ){tp = k;}}temp_max_ans += temp_f[tp];temp_f[tp] -= d[tp];if( temp_f[tp] < 0 ){temp_f[tp] = 0;}temp_ans_times[tp] += 5;}if( temp_max_ans > max_ans ){for( int i = 1; i <= N; i++ ){ans_times[i] = temp_ans_times[i];}max_ans = temp_max_ans;}}cout << ans_times[1];for( int i = 2; i <= N; i++ ){cout << ", " << ans_times[i];}cout << endl;cout << "Number of fish expected: " << max_ans << endl << endl;}return 0;}


0 0
原创粉丝点击