Gopher Game Codevs no.1245

Source: Internet
Author: User
Tags gopher

2016-05-31 18:22:32

Title Link: Gopher Game Codevs no.1245

Main topic:

At first, all the rats appeared, but the duration (s) and the points of the hit were different, finding the best strategy (1s dozen) to hit the hamster.

Solution:

Greedy + heap Optimization

Select by time, and each time the current time end of the gopher is added to the collection

Take the top point in the maximum heap per second to add the answer

Places to be aware of:

1. The chronological order must be correct, the election is wrong

1 //Gopher Games (Codevs no.1052)2 //Greedy3#include <stdio.h>4#include <algorithm>5#include <queue>6 using namespacestd;7 Const intmaxn= the;8 structnode9 {Ten     intkey; One     intTime ; A }; - node F[MAXN]; - BOOLComp (node A,node b) the { -     returnA.time>B.time; - } -Priority_queue <int>Q; + intans; - intN; + intMain () A { atscanf"%d",&N); -      for(intI=1; i<=n;i++) scanf ("%d",&f[i].time); -      for(intI=1; i<=n;i++) scanf ("%d",&f[i].key); -Sort (f+1, f+n+1, comp); -     intnow=f[1].time; -     intLoc=1; in      while(now) -     { to          while(f[loc].time==Now ) +         { - Q.push (f[loc].key); theLoc++; *         } $         if(!q.empty ())Panax Notoginseng         { -ans+=q.top (); the Q.pop (); +         } Anow--; the     } +printf"%d", ans); -     return 0; $}

Gopher Game Codevs no.1245

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.