Codevs 1052 Ground mouse game puzzle

Source: Internet
Author: User
Tags current time gopher

Ah ~ 1 days from Noip ... I haven't finished my question yet ... My template is still not proficient ... What to do ...

Let's get to the chase.


1052 Gopher Game 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, the first line contains an integer n (1<=n<=100) that indicates that there are n hamsters popping up from the ground, and the second row of n space-delimited integers indicates how long each hamster will stay after it pops up, and the third row of n spaces-delimited integers indicates the added score of each hamster 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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This problem is a greedy question ... We can use the heap (priority queue) to optimize

Greedy strategy: The current task can be completed by the time is greater than or equal to the current time, and then complete the current time to complete the larger task

The brief practice is as follows:

First of all, we first sorted by the time, and then the reverse enumeration time;

For each moment, we put all the value of the current moment into the big root heap, and then select the heap top, it is optimal;

Since we are in reverse order time, all the elements that we put into the heap are what we can do with the current time.

PS: Thank you for the idea of God ... Write in C + +, I'm really drunk ... The first Zebi God's short.

The ++++++++++++++++++++++++++++++ code is as follows ++++++++++++++++++++++++++++++++++


<span style= "Font-family:comic Sans ms;font-size:18px;" > #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue >
using namespace std;
struct node{
	int tim,w;
	BOOL operator < (Node A) const
	{
		return tim>a.tim;
	}	
} A[130];
priority_queue<int>q;
int ans,n;
int main ()
{
	scanf ("%d", &n);
	for (int i=1;i<=n;i++) scanf ("%d", &a[i].tim);
	for (int i=1;i<=n;i++) scanf ("%d", &A[I].W);
	Sort (a+1,a+n+1);
	int now=a[1].tim,k=1;
	while (now)
	{
		while (A[k].tim==now)
		{
			q.push (A[K].W);
			k++;
		}
		if (!q.empty ())
		{
			ans+=q.top ();
			Q.pop ();
		}
		now--;
	}
	cout<<ans;
	return 0;	
} </span>

There are 1 days. Go up. Juvenile. ...... Come on...




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.