Hdu2139 defend Jian Ge (simulation)

Source: Internet
Author: User
Defend Jian Ge

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 677 accepted submission (s): 141


Problem descriptiondefend Jian Ge, an interesting RPG map in war3, has a very complete equipment system as a mini RPG Game.
In the game, each player has a backpack which has 6 grids and some gold reserves. There are three kinds of equipments in the game.
1. Normal equipment: each equipment occupies one grid in the backpack and the player can buy it directly. The value of the normal equipment is equal to its price.
2. mixture equipment: each equipment occupies one grid in the backpack and the player can only get it through the synthesis of the corresponding recipe. if you have enough equipment of recipes in your backpack and gold to pay synthesis cost, you can get it.
The value of the mixture equipment is equal to the sum of all equipments 'value in the recipe plus the synthesis cost. A mixture equipment can be made from several normal equipments and mixture equipments.
3. consume equipment: a kind of equipment must occupy one grid and the player can buy it directly. that is to say, if you have a number of consume equipments, they must be in one grid. the value of each consume equipment is equal to its price, and when you
Want to handle this kind of equipment, you must wait the whole grid's equipments at the same time.

You shoshould pay attention:
1. When the backpack is full, you cannot buy anything.
2. When a mixture equipment is get, the mixture equipment of recipe in you backpack will disappear.
3. If one operation is illegal, there is nothing happened in your backpack and gold.
4. Initially, there is nothing in your backpack and you have 0 gold.
5. The gold you have cannot be a negative number.

As a DS programmer, you want to simulate the dynamic states in your backpack by program. Now you have initial State and several operations, you wonder the final state.


Inputthere are multiple test cases.
The first line contains an integer N1 (0 <= N1 <= 20) indicating the kind of normal equipment.
The next N1 lines each line contains a string and an integer indicating the name of this normal equipment and its price respectively.
** Format: Str num
The following line contains an integer N2 (0 <= N2 <= 20) indicating the kind of mixture equipment.
Each of the next N2 lines begins with a string and an integer indicating the name of this mixture Equipment and Its Synthesis cost. following, the synthesis recipe of this kind of equipment: Some pairs of string and integer indicating which kind of equipment
And the number you need to synthesis.
** Format: Str num: str1 num1, str2 num2,..., strn numn (num1 + num2 +... + Numn <= 6 and numi> = 0 (1 <= I <= n ))
The next line contains an integer N3 (0 <= N3 <= 20) indicating the kind of consume equipment.
Each of the next N3 lines contains a string and an integer indicating the name of this consume equipment and it's price.
** Format: Str num
The next line contains an integer m (0 <= m <= 100) indicating the number of operation.
Each of the next M lines contains an operation.
There are three kinds of operation:
1. + num indicating you get num gold (0 <= num <= 1000 ).
2. + STR indicating you want to get an equipment whose name is str.
3.-str indicating you want to handle the equipment whose name is str. If you want the equipment, you can get gold that is the same to its value.

There is a blank line after each case.
All strings of name only contain lowercase character and its length is no more than 15. The price of the equipment is a non-negative integer which is no more than 1000.


Outputfor each case you shoshould output several lines.
The first line output "case" + case number + ":".
The next line output an integer indicating the number of gold at last.
The next line output an integer k indicating how many grids occupied.
Each of the next K lines contain a string and an integer indicating the name and the number of the equipment. You shoshould output according to the lexicographic.
** Format: Str: num

You can get more details from the sample below.
Note: Output a blank line after each test case. 


Sample Input

[pre]2ring 1sword 21knife 3: ring 1, sword 11medicine 14+100+ring+sword+knife1shoe 01wing 1: 1medicine 13+10+shoe+wing1shoe 01wing 1: 1medicine 14+10+shoe+wing-wing1shoe 11wing 1: shoe 11medicine 18+100+shoe+shoe+shoe+shoe+shoe+medicine+medicine[/pre]
 


Sample output

[pre]Case 1:941knife: 1Case 2:92shoe: 1wing: 1Case 3:101shoe: 1Case 4:946medicine: 1shoe: 1shoe: 1shoe: 1shoe: 1shoe: 1[/pre]
 


Source2012 ACM/ICPC Asia Regional Changchun online

Abnormal simulation, all kinds of egg pain, inability to vomit, inside the ox face ....

I have been kneeling for nearly a day and have made some Sb errors, but the description of this question is serious.

Translate this question first:

Question:

1. In the initial state, a backpack, six grids, and a wallet were empty at the beginning, and the wallet was empty at the beginning.
2. Three types of equipment
3. General Equipment: A general equipment occupies a lattice in a backpack and can be purchased directly. The value is its price.
4. Synthetic equipment: One Product occupies one grid and cannot be purchased directly. According to prescription synthesis, there must be sufficient prescription equipment.
And enough gold coins, its value is the value of all raw materials and equipment and the gold coins required for synthesis, can be ordinary equipment
And synthesis equipment.
5. Equipment consumption: one type occupies one grid and can be purchased directly. To sell such equipment, you must sell all the equipment.
Note:
1. When the backpack is full, you cannot buy anything (you can synthesize it)
2. When a mixture equipment is get, the mixture equipment of recipe in you backpack will disappear: When a merging equipment is synthesized, its prescription will disappear, that is, the sentence can only be merged once. // is this sentence translated incorrectly? This is an error.
3. If an operation is invalid, the operation is invalid. It does not affect backpacks and gold coins.
4. Empty initial backpack with no gold coins
5. The number of gold coins cannot be negative.
Input:
The first line is 0 <= N1 <= 20, the number of normal equipment
Next, line N1 contains a string and a number each line, indicating the name and price of the common equipment respectively.
Then 0 <= N2 <= 20, the number of hybrid Devices
Next line N2, each line first contains a string and a number, indicating the name and Merging cost of the Hybrid device respectively.
Then, a list is provided, indicating the raw materials and quantity for merging the equipment. The total number cannot exceed 6.
Add another 0 <= N3 <= 20, indicating the number of equipment consumed
Next line N3, each line contains a string and a number, indicating the name and price of the device to be consumed.
Give another M, indicating the total number of operations
There are three operations in total:
1: ++ num, indicating the sum of money (0 <= num <= 100)
2: ++ STR, indicating that you want to get the device named STR
3: -- STR, indicating that you want to sell the STR equipment and get the corresponding gold coins.
Each name is composed of lowercase letters with a length of no more than 15. The price of each equipment is a positive integer of no more than 1000.
Output:
First output case #
Then output the final number of gold coins
Several other types of equipment are output.
Output these K types of equipment in alphabetical order
Empty output line

Question Analysis: simulation. Input is more human, especially synthetic equipment, which can be directly synthesized without raw materials. In addition, the number of raw materials for synthetic equipment can be 0... That is to say, this kind of raw material is needed, but this kind of raw material is not consumed. In addition, you must first buy and merge the purchased equipment. If the backpack is full, you cannot buy it.

This is a good simulation, but the description of the question instantly drops the grade of this question ..

For details, see the code:

# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; struct norequ {char name [16]; int price ;} normal [21]; struct OBJ {char name [16]; int num, price; friend bool operator <(struct obj a, struct obj B) {return strcmp (. name, B. name) <0 ;}}obj [7]; int total; bool del [10]; struct mix {char name [16]; int cost; int CNT; bool flag; int num [6]; // raw material quantity char sname [6] [16]; // raw material Name} mixture [21]; struct con {char name [16]; int price;} consume [21]; int gold; int m; char equp [20]; int nornum, mixnum, connum; void show () {printf ("let's show: \ n"); int I, j; printf ("Normal: \ n "); for (I = 0; I <nornum; I ++) printf ("% S % d \ n", normal [I]. name, normal [I]. price); printf ("\ n"); printf ("mixture: \ n"); for (I = 0; I <mixnum; I ++) {printf ("% S % d \ n", mixture [I]. name, mixture [I]. cost); printf ("the % DTH mixt Ure is consist of: \ n ", I); For (j = 0; j <mixture [I]. CNT; j ++) printf ("% S % d \ n", mixture [I]. sname [J], mixture [I]. num [J]);} printf ("\ n"); printf ("consume: \ n"); for (I = 0; I <connum; I ++) {printf ("% S % d \ n", consume [I]. name, consume [I]. price);} printf ("show off \ n");} void output (int cas) {printf ("case % d: \ n", CAS ); printf ("% d \ n", gold); printf ("% d \ n", total); sort (OBJ, OBJ + total); For (INT I = 0; I <total; I ++) Printf ("% s: % d \ n", OBJ [I]. name, OBJ [I]. num); putchar (10);} int find (char SSS []) // locate the item type {int I; for (I = 0; I <nornum; I ++) {If (strcmp (SSS, normal [I]. name) = 0) return I ;}for (I = 0; I <mixnum; I ++) {If (strcmp (SSS, mixture [I]. name) = 0) return 30 + I;} for (I = 0; I <connum; I ++) {If (strcmp (SSS, consume [I]. name) = 0) return 60 + I;} return-1;} int canmix (INT ID) {If (mixture [ID]. CNT = 0) RET Urn 0; int I, j, k; int ret = 0; bool lll = false; for (I = 0; I <mixture [ID]. CNT; I ++) {k = mixture [ID]. num [I]; for (j = 0; j <total; j ++) {If (strcmp (mixture [ID]. sname [I], OBJ [J]. name) = 0) {If (OBJ [J]. num <= mixture [ID]. num [I]) // during synthesis {// raw material consumption, the synthetic item can be put into the backpack lll = true;} k-= OBJ [J]. num;} If (k <= 0) // the raw material is break enough;} If (k> 0) // the raw material is not enough. Return-1 ;} if (lll = false & Total = 6) // If the backpack is full but the raw materials cannot be made up Return-1; return 0;} void mixit (int id) {If (mixture [ID]. CNT = 0) return; int I, j, k; memset (Del, false, sizeof (DEL); for (I = 0; I <mixture [ID]. CNT; I ++) {k = mixture [ID]. num [I]; If (! K) continue; For (j = 0; j <total; j ++) {If (strcmp (mixture [ID]. sname [I], OBJ [J]. name) = 0) {If (OBJ [J]. num> K) {OBJ [J]. num-= K; k = 0;} else {del [J] = true; // Mark K-= OBJ [J] for deletion. num;} If (k = 0) break;} int Pos = 0; for (I = 0; I <total; I ++) {If (DEL [I] = false) OBJ [POS ++] = OBJ [I];} Total = Pos;} int getprice (INT type) // because the raw material of the synthesized item can also be a synthetic item, the value of {If (type <30) return normal [type] should be calculated recursively. pric E; If (type> = 60) return consume [type-60]. price; int I; int ret = 0; for (I = 0; I <mixture [type-30]. CNT; I ++) {int TMP = find (mixture [type-30]. sname [I]); RET + = mixture [type-30]. num [I] * getprice (TMP);} return ret + mixture [type-30]. cost;} void buy (INT type) {If (type <30) {If (Total = 6 | gold <normal [type]. price) return; strcpy (OBJ [total]. name, normal [type]. name); OBJ [total]. num = 1; OBJ [total]. price = normal [type]. price; Total ++; gold-= normal [type]. price; return;} If (type >=30 & type <60) // mixture [type-30]. flag) {If (Gold <mixture [type-30]. cost) // return; int TMP = canmix (Type-30); If (TMP =-1) return; TMP = getprice (type ); gold-= mixture [type-30]. cost; mixit (Type-30); OBJ [total]. price = TMP; OBJ [total]. num = 1; strcpy (OBJ [total]. name, mixture [ty Pe-30]. name); Total ++; mixture [type-30]. flag = false; // only once} If (type >=60) {If (Total = 6 | gold <consume [type-60]. price) // purchase consumables before merging return; gold-= consume [type-60]. price; For (INT I = 0; I <total; I ++) {If (strcmp (OBJ [I]. name, equp) = 0) {OBJ [I]. num ++; return ;}} strcpy (OBJ [total]. name, consume [type-60]. name); OBJ [total]. num = 1; OBJ [total]. price = consume [type-60]. price; Total ++; return ;}} void aggregate (INT type) {int I; for (I = 0; I <total; I ++) {If (strcmp (equp, OBJ [I]. name) = 0) break;} if (I = total) // unfind return; If (type <30) {Gold + = OBJ [I]. price; For (Int J = I + 1; j <total; j ++) OBJ [J-1] = OBJ [J]; Total --; return ;} if (type> = 30 & type <60) {Gold + = OBJ [I]. price; For (Int J = I + 1; j <total; j ++) OBJ [J-1] = OBJ [J]; Total --; return ;} if (type> = 60) {Gold + = OBJ [I]. price * OBJ [I]. num; For (Int J = I + 1; j <total; j ++) OBJ [J-1] = OBJ [J]; Total --; return ;}} int main () {int I; char C; char op [20]; int CAS = 0; while (scanf ("% d", & nornum )! = EOF) {Gold = 0; Total = 0; for (I = 0; I <nornum; I ++) {scanf ("% S % d ", normal [I]. name, & Normal [I]. price);} scanf ("% d", & mixnum); getchar (); for (I = 0; I <mixnum; I ++) {char STR [200]; gets (STR); // fortunately, sscanf int p = 0; int TMP = 0; sscanf (STR + P, "% S % d", mixture [I]. name, & Mixture [I]. cost); While (STR [p] & STR [p]! = '') P ++; while (STR [p] & STR [p]! = '') P ++; while (sscanf (STR + P," % S % d ", mixture [I]. sname [TMP], & Mixture [I]. num [TMP]) = 2) {TMP ++; If (mixture [I]. num [TMP-1] = 0) TMP --; while (STR [p] & STR [p] = '') P ++; while (STR [p] & STR [p]! = '') P ++; while (STR [p] & STR [p]! = '') P ++;} mixture [I]. CNT = TMP; mixture [I]. flag = true;} scanf ("% d", & connum); for (I = 0; I <connum; I ++) {scanf ("% S % d ", consume [I]. name, & consume [I]. price);} // show (); scanf ("% d", & M); getchar (); While (M --) {gets (OP ); if (isdigit (OP [1]) {sscanf (OP + 1, "% d", & I); If (OP [0] = '+ ') gold + = I; else {If (Gold> = I) Gold-= I ;}} else {sscanf (OP + 1, "% s", equp ); int type = find (equp); If (type =-1) continue; If (OP [0] = '+') Buy (type ); else round (type) ;}} output (++ CAS) ;}return 0 ;}// 0ms260k/* 2 ring 1 sword 21 knife 3: ring 1, sword 11 medicine 15 + 100 + ring + sword + knife2ring 1 sword 21 knife 3: ring 1, sword 11 Medicine 14 + 100 + ring + sword + knife1shoe 01 Wing 1: 1 medical 13 + 10 + shoe + wing1shoe 01 Wing 1: 1 medical 14 + 10 + shoe + wing-wing1shoe 11 Wing 1: shoe 11 medicine 18 + 100 + shoe + medicine + medicine2ring 1 sword 21 knife 3: ring 1, sword 11 Medicine 14 + 100 + ring + sword + knife2ring 1 sword 21 knife 3: Ring 2, sword 11 medicine 15 + 100 + ring + sword + knife2ring 1 sword 21 knife 3: ring 1, sword 11 medicine 15 + 100 + ring + sword + knife-knife2ring 1 sword 21 knife 3: ring 1, sword 11 medicine 15 + 100 + ring + sword + knife-sword1shoe 01 Wing 1: 1 medical 13 + 10 + shoe + wing1shoe 01 Wing 1: 1 medical 14 + 10 + shoe + wing-wing1shoe 11 Wing 1: shoe 11 medicine 17 + 100 + shoe + medicine + medicine1shoe 11 Wing 1: shoe 11 medicine 18 + 100 + shoe + medicine-medicine */

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.