Test instructions: Recently, the loss of losing weight for the vent heart depressed, playing a game to eliminate the child-free.
The rules of the game are simple, kill the child with arrows.
Arrow is a consumable, known to have M different types of arrows can be selected, and each arrow will damage the rabbit, the corresponding damage value is di (1 <= i <= M), each arrow needs a certain amount of QQ coins to buy.
Assuming that each arrow can only be used once, each child can only be shot once, please calculate to eliminate all the rabbits on the map of the minimum required QQ currency.
Link: Point Me
Greedy in the arrows that can kill a rabbit, choose the lowest price
First Direct two for,tle, after reading the code of others to know with priority queue
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5#include <cmath>6#include <queue>7#include <map>8 using namespacestd;9 #defineMOD 1000000007Ten Const intinf=0x3f3f3f3f; One Const Doubleeps=1e-5; A #defineCL (a) memset (A,0,sizeof (a)) - #defineTS printf ("*****\n"); - Const intmaxn=100005; the intB[MAXN],D[MAXN],P[MAXN]; - intN,m,tt; - structnode - { + intd,p; - }A[MAXN]; + BOOLCMP1 (node A,node b) A { at returnA.d>B.D; - } - structCMP - { - BOOL operator()(intXinty) - { in returnX>y; - } to }; +priority_queue<int,vector<int>,cmp >Q; - BOOLVIS[MAXN]; the intMain () * { $ inti,j,k;Panax Notoginseng #ifndef Online_judge -Freopen ("1.in","R", stdin); the #endif + while(SCANF ("%d%d", &n,&m)! =EOF) A { the while(!q.empty ()) Q.pop (); + for(i=0; i<n;i++) scanf ("%d",&b[i]); - for(i=0; i<m;i++) scanf ("%d",&a[i].d); $ for(i=0; i<m;i++) scanf ("%d",&A[I].P); $Sort (b,b+n); -Sort (a,a+m,cmp1); - Long Longans=0; the BOOLf=1; - intt=0;Wuyi for(i=n-1; i>=0; i--) the { - while(t<=m-1&&a[t].d>=B[i]) Wu { - Q.push (A[T].P); Aboutt++; $ } - if(Q.empty ()) - { -f=0; A Break; + } theans+=q.top (); - Q.pop (); $ } the if(!f) printf ("no\n"); the Elseprintf"%i64d\n", ans); the } the}
HDU 4544 Priority Queue + greedy