MaginaTime
limit:60000/30000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 528 Accepted Submission (s): 177
Problem Descriptionmagina, also known as Anti-mage, is a very cool hero in DotA (Defense of the Ancient).
If you have the no idea of him, this is some brief introduction of his legendary antecedents:
Twin Sons to the great Prophet, Terrorblade and Magina were blessed with divine Powers:terrorblade granted with an Unnatu RAL affinity with life forces; Magina gifted with energy manipulation. Magina ' s eventual overexposure to the magic gradually augmented his elemental resistances and bestowed him the unique Abil ity to move faster than light itself. Now, broken by Terrorblade's fall to the dark side, Magina answers the Sentinel's call in a desperate bid to redeem his BR Other. Every bitter strike turns the Scourge ' s evil essences upon themselves, culminating in a finale that forces he enemy to AW Aken to the void within and spontaneously implode.
Magina have a very IMBA (imbalanced) Skill–blink, yes, move from one place to another place in a wink. Our problem begins at there.
As a formidable hero in the later stage, Magina always farm with the wild monsters for a long time. The farming more efficient, Magina use Blink frequently and there. Here we assume Blink skill have no CD, that's, we can use this skill at any time we want.
There is N spots of the wild monsters, and Magina can choose any one to begin. For every spots, Magina if Ti time to kill the monsters and gain Gi units money, or he choose blink to other spots, W Hich is known to our brilliant magina. If the monsters in a spot were killed, it won ' t appear any more.
Now Magina want to get M units money to but some excellent equipment, say Battle Fury for example. As a hero to save the world, there are no much time left for Magina, he wonders the minimum time for him to gain at least M Units money.
Inputthe first line contains a single integer T, indicating the number of test cases.
Each test case is begins with the integers N, M. Their meanings is the same as the description.
Then N blocks follow, each one describes a spot of wild monsters.
The first line of each block is there integers Ti, Gi and Ki. Ti is the time, Gi was the units of money, Ki was the number of spots Magina can blink to from here.
Then Ki integer Cij Follow, indicating the spots ' ID Magina can blink to. You may assume no ID would appear twice.
The spots is described with ID increasing from 1 to N. Input ensure if you can blink from I-J, you can also blink from J to I.
Technical specification
1.1 <= T <= 50
2.1 <= N <= 50
3.1 <= Ti <= 10000000
4.1 <= M, Gi <= 1000000000
5.1 <= Ki < N
6.1 <= Cij <= N
Outputfor each test case, output the case number first, then the minimum time for Magina to gain at least M units money, I F can ' t, output "Poor Magina, you can ' t save the World all the time!”.
Sample Input
31 42 5 01 51 4 04 101 9 03 3 133 3 22 44 4 13
Sample Output
Case 1:2case 2:poor Magina, your can ' t save the World all the time! Case 3:10Main Topic : The title originates from DotA, before a heap of introduction enemy Mage, the last section began to say there are n heaps of beasts, each heap of beast Slaughter finished need to spend TI time, can increase the money gi, enemy Mage has teleport skills, can move from a pile of beasts to another pile of beasts, the topic given a connected point. Finally ask for the least amount of time in case of getting money m.
Thinking of solving problems : using a deep search to find the connected sub-graph, and then slaughter the nodes in the connected sub-graph, there are two options for each beast: Kill and not kill. This problem turns into a 01 backpack.
But the subject of money and slaughter time range is particularly large, the scope of slaughter time is 110 million, the range of money is 11 billion, can not use the conventional double cycle simulation. In fact, with two priority queue can be simulated 01 knapsack calculation process, the first time (0,0) to the queue, and then out of the team to move to the next state, the transfer of the two states are queued, you can use two priority queue to operate, one represents the previous round of calculation results, one is this round, equivalent to the scrolling array. In the process of simulation with the priority queue to pay attention to pruning, if not cut or cut bad is the MLE. There is only one, that is, each time the transfer to the queue 1 to the queue 0, the judgment of this point is not satisfied with the value of the team in front of the point of money and less time-consuming, if so, this may be better than the previous team, if not, this must not be added to the queue, Since the current state money is less than the amount of money to enter the queue, and when the time is equal or more, then to enter a node when the update must not have advanced queue State excellent . For example, (6,4) that hit the money to 6, and time-consuming 4, if the next to enter the team is (5,5), it must be the front of the better, right? That's it.
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <string.h >using namespace Std;const int inf=0xfffffff;struct node{int t,g; friend bool operator< (node A,node b) {if (A.G==B.G) return a.t>b.t; Return a.g<b.g; }};int vist[55],m,ans;vector<int>tmap[55];p riority_queue<node>q[2];node val[55];void dfs (int x) {node p, Tp Vist[x]=1; while (!q[0].empty ()) {p=q[0].top (); Q[0].pop (); Q[1].push (P); P.G+=VAL[X].G; p.t+=val[x].t; if (p.g>=m) {if (ans>p.t) ans=p.t; continue; } if (ANS<=P.T) continue; Q[1].push (P); } Tp.t=ans; while (!q[1].empty ()) {p=q[1].top (); Q[1].pop (); if (tp.t>p.t) Q[0].push (p), tp=p; } for (int i=0;i<tmap[x].size (); i++) {int j=tmap[x][i]; if (Vist[j]) continue; DFS (j); }}int Main () {int t,n,k,u; Node p; scanf ("%d", &t); for (int c=1;c<=t;c++) {scanf ("%d%d", &n,&m); for (int i=1;i<=n;i++) {tmap[i].clear (); vist[i]=0; scanf ("%d%d%d", &val[i].t,&val[i].g,&k); while (k--) {scanf ("%d", &u); Tmap[i].push_back (U); }} Ans=inf; for (int s=1;s<=n;s++) if (vist[s]==0) {while (!q[0].empty ()) Q[0].pop (); while (!q[1].empty ()) Q[1].pop (); p.g=p.t=0; Q[0].push (P); DFS (s); } printf ("Case%d:", c); if (ans!=inf) printf ("%d\n", ans); else printf ("Poor Magina, you can ' t save the World of the Time!\n"); }}
HDU3810 Magina (search + with priority queue Simulation 01 backpack) Classic