Owner problem, owner duver

Source: Internet
Author: User

Owner problem, owner duver
Destroyer problem time limit: Memory ms single point time limit: Ms memory limit: MB description

In the frozen throne of Warcraft III, the owner is a magic flying unit from the last three hours of a zombie fight.

Absorb Mana ):

Now let's consider the following:

Assume that you haveNA magic unit. They stand in a row from left, numbered from 1N. Each organization has three attributes:

 

  • SI: Initial mana.

  • MI: Maximum mana limit.

  • RI: The speed at which China and France reply each second.

 

Now you manipulate a destroyerMOperations,T L R, Indicating the time t. The Destroyer starts fromLToRUnit, which is absorbed by magic. The operation is given in chronological order to calculate the total amount of mana absorbed by the Destroyer.

 

Input

The first line of the input data has an integer.N(1 hour ≤ hourN ≤ 105)-The number of your magic units.

NextNRow. Each row has three integers.SI, Bytes,MI, Bytes,RI(0 bytes ≤ bytesSILimit ≤ limitMILimit ≤ limit 105, 0 limit ≤ limitRILimit ≤ limit 105) describes a magic unit.

The next row is an integerM(1 digit ≤ DigitMOperation ≤ limit 105),-number of operations.

NextMLine. Each line describes an operation.T, Bytes,L, Bytes,R(0 bytes ≤ bytesTLimit ≤ limit 109, 1 limit ≤ limitLLimit ≤ limitRLimit ≤ limitN),TNon-downgrade.

 

Output

An integer in the output line indicates the total amount of mana absorbed by the owner.

Sample Input
50 10 12 10 20 10 12 10 10 125 1 519 1 5
Code:
1 import java. util. keys; 2 3 4 public class Destroyer {5 6 7 8 public static void main (String argv []) {9 10 blocks br = new blocks (System. in); 11 // obtain the magic unit data 12 int n = Integer. parseInt (br. nextLine (); 13 int energy = 0; 14 String [] N = new String [n]; 15 for (int I = 0; I <n; I ++) {16 17 N [I] = br. nextLine (); 18 19} 20 21 // get operation group 22 int m = Integer. parseInt (br. nextLine (); 23 String [] M = new String [m]; 24 for (int I = 0; I <m; I ++) {25 26 M [I] = br. nextLine (); 27 28} 29 br. close (); 30 31 // data is converted to the magic unit object group 32 Mor [] Mer = new Mor [n]; 33 for (int I = 0; I <n; I ++) {34 String [] List = N [I]. split (""); 35 Mer [I] = new Mor (Integer. parseInt (List [0]), Integer. parseInt (List [1]), Integer. parseInt (List [2]); 36 // System. out. println (Mer [I]. s + Mer [I]. speed + Mer [I]. max); 37} 38 39 // data is converted to the operation object group 40 Mov [] Mver = new Mov [m]; 41 for (int I = 0; I <m; I ++) {42 String [] List_v = M [I]. split (""); 43 Mver [I] = new Mov (Integer. parseInt (List_v [0]), Integer. parseInt (List_v [1]), Integer. parseInt (List_v [2]); 44 // System. out. println (Mver [I]. time + Mver [I]. first + Mver [I]. end); 45} 46 47 // The time period is 48 for (int I = m-1; I> = 1; I --) {49 50 Mver [I]. time = Mver [I]. time-Mver [I-1]. time; 51 52} 53 54 // computation draws magic 55 for (int I = 0; I <m; I ++) {56 // calculate the magic number of each operation: 57 for (int j = 0; j <n; j ++) {58 Mer [j]. s = Mer [j]. s + Mer [j]. speed * Mver [I]. time; 59 if (Mer [j]. s> = Mer [j]. max) 60 Mer [j]. s = Mer [j]. max; // the magic number cannot exceed the maximum 61 if (j + 1 <= Mver [I]. end & j + 1> = Mver [I]. first) {62 energy = energy + Mer [j]. s; // magic absorbed 63 Mer [j]. s = 0; 64 // System. out. println (energy); 65} 66 67} 68} 69 System. out. println (energy); // output the learned magic value 70 71} 72 73} 74 75 // define the magic unit object 76 class Mor {77 78 int s; 79 int speed; 80 int max; 81 Mor (int a, int B, int c) {82 this. s = a; 83 this. speed = c; 84 this. max = B; 85} 86} 87 // define the operation object 88 class Mov {89 90 int time; 91 int first; 92 int end; 93 Mov (int a, int B, int c) {94 this. time = a; 95 this. first = B; 96 this. end = c; 97} 98}

Running effect:

 

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.