757-Gone Fishing

Source: Internet
Author: User

[Cpp]
Description: Brute Force + greedy. You can only select the first and second lakes in turn ...... The last Lake becomes the problem of selecting the optimal solution. You can select the optimal solution and the largest one. Note that the data may be zero, this is to use all the time in the first Lake.
# Include <cstdio>
# Include <cstring>
Int main ()
{
// Freopen ("a.txt", "r", stdin );
Int t [30], f [30], d [30], s [30];
Int h, n, count, p = 0;
While (scanf ("% d", & n )! = EOF)
{
If (! N) break;
If (p) printf ("\ n ");
Scanf ("% d", & h );
H * = 60;
For (int I = 0; I <n; I ++) scanf ("% d", & f [I]);
For (int I = 0; I <n; I ++) scanf ("% d", & d [I]);
Count = t [0] = 0;
For (int I = 1; I <n; I ++)
{
Scanf ("% d", & t [I]);
T [I] = t [I] * 5 + t [I-1];
}
Memset (s, 0, sizeof (s ));
For (int I = 0; I <n; I ++)
{
Int leave = h-t [I];
If (leave <5) break;
Int sum = 0, pos = 0, temp [30], m [30], flag, c;
For (int j = 0; j <= I; j ++)
{
M [j] = f [j];
Temp [j] = 0;
}
While (leave> = 5)
{
Flag = c = 0;
For (int j = 0; j <= I; j ++)
If (m [j]> c)
{
C = m [j];
Pos = j;
Flag = 1;
}
If (! Flag) break;
Temp [pos] + = 5;
Sum + = c;
M [pos]-= d [pos];
Leave-= 5;
}
If (leave> = 5) temp [0] + = leave;
If (sum> count)
{
Count = sum;
For (int j = 0; j <= I; j ++) s [j] = temp [j];
}
}
If (! Count) s [0] = h;
Printf ("% d", s [0]);
For (int I = 1; I <n; I ++) printf (", % d", s [I]);
Printf ("\ nNumber of fish expected: % d \ n", count );
P ++;
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.