Title Description
Description
Wang Gang is a student of excellent academic performance, in peacetime learning, he can always use all the time to study seriously and efficiently, he not only study hard, but also good at often summarize, improve their learning methods, so he always in every exam to get excellent scores, which is largely because he is a pursuit of efficiency of the people.
But Wang Gang is also a like to play, usually in school he tried to restrain himself to play, but in Sunday he will smoke a certain time to let himself play, his father and mother also more trust in his learning ability and learning habits, so in Sunday will not like other parents on his grasp, Instead, he was allowed to spend his free time in the morning of Sunday.
The Gopher game is a game that requires speed and agility in response. At the beginning of the game, there will be a lot of rats on the floor, and then when you use a hammer to tap these hamsters, each hamster is hit, will increase the corresponding game score. The problem is that these hamsters will not wait for you to knock, it will always come out after a while to drill under the floor (and never come up), each hamster to stay after the time may be different, and each ground mouse is hit after the increased game score may be different, in order to win, Game participants have to selectively tap some hamsters as soon as possible, depending on the characteristics of each gopher, making the total score the most.
This challenging game Wang gang especially liked, recently he often played this game in Sunday morning, slowly he not only hit faster and faster (the time required to tap each gopher is 1 seconds), and he also found some features of the game, that is, every time the game starts again, A hamster's time to stay is fixed, and he records the number of points that will be added to each hamster when struck. As a result, he always chooses to hit different hamsters at the beginning of each game, ensuring that the maximum score is obtained each time.
Enter a description input
Description
The input contains 3 rows, and the first row contains an integer n(1<=n<=100) that indicates n a gopher emerges from the ground, and the second line N a space-delimited integer that indicates how long each hamster stays after it pops up, and the third row N a space-delimited integer that indicates the number of points that will be added to each gopher after being struck ( <=100 ). The number of I in each row represents The information of the I gopher.
outputs description output
Description
The output is a single integer, representing the maximum game score that Wang Gang can get.
sample input to
sample
5
5 3 6) 1 4
7 9 2) 1 5
Sample output Sample
outputs
24
data
size & Hint just see the problem, a feeling is moving back, wrote a will only after 6 sets of data, debugging half a day can not, and then read the puzzle to find is greedyfirst write a structure to store the information of the hamster, and then we follow the score from the big to the small sortand then from the big to the small to start the traversal, in the addition of a layer of circulation from the time to hit the hamster at the latest moment to push forwardIf the time is not marked, then the minute is added to the final score, and then the time is marked.
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;struct mouse{int w,t;} A[105];bool CMP (Mouse a,mouse b) {return A.W>B.W;} int main () {bool D[105];memset (d,0,sizeof (d)); int n, ans = 0;scanf ("%d", &n), for (int i=0;i<n;i++) scanf ("%d", &A[I].T), for (int i=0;i<n;i++) scanf ("%d", &A[I].W), sort (a,a+n,cmp), and for (int i=0;i<n;i++) {-int j=a[i ].t;j>=1;j--) if (!d[j]) { d[j]=true; ANS+=A[I].W; break; }} printf ("%d\n", ans); return 0;}
Gopher Game---Greedy