Bzoj 3875: [Ahoi2014] Knight Game

Source: Internet
Author: User

D[i] Represents the minimum physical value required to destroy I, d[i] = min (S[i], k[i]+σd[x]), Σd[x] represents the other monsters produced by ordinary attacks. Because it is not a DAG, the answer is updated with a queue similar to SPFA.

--------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>   using namespace std;   typedef long Long ll;   const int MAXN = 200009;   int N, q[10000000];;ll D[MAXN], A[MAXN], B[MAXN];bool INQ[MAXN];   struct Edge {int t;edge* N;} e[2000009], *pt = E, *H[MAXN], *FIR[MAXN];   inline void Addedge (edge* h[], int u, int v) {pt->t = V, pt->n = H[u], h[u] = pt++;}   void Init () {scanf ("%d", &n);int num, t;for (int i = 0; i < N; i++) {scanf ("%lld%lld%d", A + i, B + i, &num);While (num--) {scanf ("%d", &t), t--;Addedge (H, I, t);Addedge (Fir, T, i);}}}   void Work () {int h = 0, t = 0, X;for (int i = 0; i < N; i++)Inq[i] = True, q[t++] = i;While (H < T) {inq[x = q[h++]] = false;ll sm = 0;For (edge* e = h[x]; e; e = e->n)if (sm + = b[e->t]) >= b[x]) break;if (SM + a[x] < b[x]) {B[x] = SM + a[x];For (edge* e = fir[x]; e; e = e->n)if (!inq[e->t]) q[t++] = e->t, inq[e->t] = true;}}printf ("%lld\n", B[0]);}   int main () {Init ();Work ();return 0;}

--------------------------------------

3875: [Ahoi2014] Knight game time Limit: $ Sec Memory Limit: + MB
Submit: 274 Solved: 148
[Submit] [Status] [Discuss] Description "Story Background" in the long-term otaku life, Jyy also dug out an RPG game. In this game jyy will play a heroic knight, with his sword in his hand to kill the invading village monsters. "Description of the problem" in this game, jyy altogether has two kinds of attack way, one is the common attack, one is the spell attack. Both attacks consume jyy of energy. Attacking a monster with a normal attack does not kill the beast completely, the corpse of the monster can be made out of some other new monsters, notice that a monster may change back to one or more of the same monsters after several ordinary attacks, while a spell attack can kill a monster completely. Of course, in general, spell attacks consume more stamina than normal attacks (but this is not guaranteed due to game system bugs). There are a total of n different monsters in the game world, numbered from 1 to N, and now the monster 1th has invaded the village, and Jyy wants to know at least how much stamina it takes to kill all the monsters in the village. Input

The first line contains an integer n. Next n lines, each line describes a monster's information, where line I contains several integers, the first three integers are Si,ki and ri, which means that for monster I, the normal attack requires the energy of SI, the spell attack consumes Ki's strength, and the monster I will produce a new monster after death. Represents a new monster number that appears. The same number of monsters can appear multiple. Output

Outputs a single integer that represents the minimum required physical value.

Sample Input4
4 27 3 2 3 2
3 5 1 2
1 13 2) 4 2
5 6 1 2Sample Output -HINT

"Sample description"
First use the 4-point stamina with a common attack, then the monster numbers that appear are 2,2 and 3. Spend
10-point stamina kills two monsters with a spell attack that is numbered 2. The remaining 3rd Monsters cost 1 stamina.
Normal attacks. In this case, the monsters in the village are numbered 2 and 4. Finally, it costs 11 mana to attack.
Kill the two monsters completely. The total cost of energy is 4+5+5+1+5+6=26.
"Data Range"
2<=n<=2*10^5,1<=ri,sigma (Ri) <=10^6,1<=ki,si<=5*10^14

Source

by anonymous upload

Bzoj 3875: [Ahoi2014] Knight Game

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.