The Legend of CCF2016093 Furnace stone (c language Edition)

Source: Internet
Author: User
Tags strcmp

Description of the Problem: "the legend of the stone, the hero of warcraft" (hearthstone:heroes of warcraft, referred to as the legend of the Furnace) is Blizzard Entertainment development of a set of card game (as shown). The game is performed on a battle board, which is operated by two players in turn, and the simplified rules for the legend of the stone used in the game are as Follows:

* Players will control some characters, each with their own health and ATTACK. When the health value is less than or equal to 0 o'clock, the role dies. Characters are divided into heroes and Followers.
* Each player controls a hero, when the game starts, the Hero's health value is 30, the attack damage is 0. When the hero dies, the game is over and the Hero's dead side wins.
* Players can summon followers during the Game. Each side of the board has 7 slots that can be used to place the entourage, from left to right, called the BATTLEFIELD. When the attendant dies, it is removed from the BATTLEFIELD.
* After the game starts, two players take turns, and each player's successive set of actions is called a round.
* In each turn, the current player can perform 0 or more of the following actions:
1) Summon Attendant: The player summons an attendant to enter the battlefield, with the attendant having the specified health value and ATTACK.
2) Entourage Attack: The player controls one of his followers attacking the Opponent's hero or an Entourage.
3) End turn: The player declares that his current turn is over and the game will enter the Opponent's Turn. The operation must be the last action of a Turn.
* When an attendant attacks, the attacker and the attacker will simultaneously inflict damage on each other equal to their attack. The health of the injured character will be reduced, and the value is equal to the damage being Received. For example, the attendant X's health value is HX, The attack is AX, the attendant Y's health value is HY, the attack is AY, if the attendant X attack companion y, then after the attack after the health of X to hx-ay, the health of the attendant y becomes hy-ax. After an attack occurs, the health value of the role can be Negative.
The subject will give a game process, requiring the program to simulate the game process and output the final Situation. Input format input The first line is an integer n, which indicates the number of Operations. Next n rows, Each line describes an operation in the following format:
<action> <arg1> <arg2> ...
Where <action> represents the type of operation, is a string, a total of 3 kinds: summon means summon entourage, attack represents a companion attack, end represents the end of the Round. The specific format of these 3 operations is as Follows:
* Summon <position> <attack> * Attack <attacker> <defender&gt: current player's role <attacker> attacking opponent's role <defender>. <attacker> is an integer from 1 to 7, indicating that the Attack's attendant number,<defender> is a 0 to 7 integer representing the attacking Opponent's role, 0 means attacking the Opponent's hero, and 1 to 7 indicates the number of the Attacker's Entourage.
* End: current player ends this Turn.
Note: the number of the attendant will change as the game progresses, and when a follower is summoned, the player designates the position of the follower to be placed in the battlefield, at which point the same position and all attendant numbers on the right are incremented by 1. When an attendant dies, all attendant numbers on the right side of it are reduced by 1. At any moment, the followers of the battlefield always numbered consecutively from 1 ONWARDS. Output format output total 5 rows.
The 1th line contains an integer that indicates the outcome of the game after the nth operation (hereinafter referred to as the T-moment), 1 means that the player wins, 1 means the player wins, and 0 means the game is not over, and no one has Won.
The 2nd line contains an integer that represents the life of the hero of the player at the T Moment.
The 3rd line contains several integers, and the first integer p represents the number of followers that the player survives on the battlefield at the T moment, followed by P integers, which represent the lives of those companions at t time (in order from left to right).
Lines 4th and 5th are similar to lines 2nd and 3rd, except that players are replaced by players from the Initiator. Sample Input 8
Summon 1 3 6
Summon 2 4 2
End
Summon 1 4 5
Summon 1 2 1
Attack 1 2
End
Attack 1 1 Example output 0
30
0 S
30
1 2 Sample Description Follow the Line-by-row interpretation of the sample input starting from line 2nd as Follows:
1. The initiator player in position 1 summon a health value of 6, attack 3 of the Entourage a, is the only entourage of the party on the BATTLEFIELD.
2. In position 2, the player summons a companion B with a health value of 2 and a damage of 4, appearing on the right side of Entourage A.
3. The player turn ends at the Initiator.
4. The player in position 1 summon a health value of 5, attack 4 of the attendant C, is the only entourage on the BATTLEFIELD.
5. The player in position 1 summons a health value of 1, attack 2 of the attendant D, appears on the left of the Entourage C.
6. Entourage D Attacks Entourage B, both of whom Die.
7. The player turn ends.
8. With a attack attendant C, the health of both sides decreased to 2. Evaluation of use case size and contract * Number of operations 0≤n≤1000.
* The initial health of the entourage is an integer from 1 to 100, with a damage of 0 to 100.
* Ensure that all operations are lawful, including but not limited to:
1) the location of the summoned Entourage must be lawful, that is, if there is an M attendant on the battlefield of the current party, then the location of the summoned entourage must be between 1 to M + 1, where 1 represents the leftmost position of the battlefield, and M + 1 represents the rightmost position of the BATTLEFIELD.
2) when there are 7 followers in the battlefield, no new followers will be Summoned.
3) the attacking and attacking roles must be present, and the attacking role will attack more than 0.
4) If a hero dies, there will be no further action.
* Data contract:
The first 20% of the evaluation cases summon the entourage to the far right of the BATTLEFIELD.
The first 40% evaluation cases do not have attack operations. The first 60% of the evaluation cases do not have the attendant death Situation.

Problem solving Ideas:

Set up a two-dimensional array to simulate the game scene, giving the hero and entourage a place to mark, as shown in:

See the following code for detailed ideas

1#include <stdio.h>2#include <string.h>3 4 structrole{//Create a companion data structure5     intAttack//Attack6     intHealth//Blood Volume7 };8 structRole player[2][8];//create a two-dimensional array store heroes and followers of both sides9 introle_num[2] = {0,0};//indicates the number of roles for each partyTen  one voidSummon (intwho,intPosintatt,inthea); a voidDeleteintwho,intpos); - voidAttackintwho,intpos1,intpos2); - intMainvoid) { the     inti, j,pos, att, hea,n; -     intattacker, defender; -     Charcmd[ the]; -     intwho =0 ; +player[0][0].attack =0;//Initialize the blood and attack of both heroes -player[0][0].health = -; +player[1][0].attack =0; aplayer[1][0].health = -; atscanf"%d",&n); -      while(n--) -     { -scanf"%s", cmd); -         if(STRCMP (cmd,"Summon") ==0) -{//Summon chitian, Summoning Entourage inscanf"%d%d%d",&pos,&att,&hea); - Summon (who,pos,att,hea); to         } +         if(STRCMP (cmd,"Attack")==0) -{//Attack thescanf"%d%d", &attacker,&defender);//attacker represents the location of the attacker, defender indicates the location of the attacker *Attack (who,attacker,defender);//attack, who indicates which side is attacking, initial who = 0, indicates the initiator attack $         }Panax Notoginseng         if(STRCMP (cmd,"End")==0) -who =1-who;//Chitian end, Change the other side operation, who = 1-who the     } +      a     if(player[0][0].health>0&& player[1][0].health<=0)//after all operations, compare the blood of both heroes to determine the outcome theprintf"1\n"); +     Else if(player[0][0].health<=0&& player[1][0].health>0) -printf"-1\n"); $     Else $printf"0\n"); -      for(i =0; I <2; I++)//print the number of roles on both sides, blood volume -     { theprintf"%d\n", player[i][0].health); -printf"%d", role_num[i]);Wuyi          for(j =1; J <= role_num[i]; J + +) the         { -printf"%d", player[i][j].health); wu         } -printf"\ n"); about     } $     return 0; - } -  - voidSummon (intwho,intPosintatt,intHea) a{//Summon function, who represents the summoning party, POS indicates where to summon, att means Entourage attack, Hea represents the amount of blood +     inti; the     if(pos >0)//the summoned Entourage is only on the right of the Hero. -     { $role_num[who]++;//each call, the number of characters plus 1 the          for(i = role_num[who]; i > pos; i--) the{//position Pos and right attendant all move one position to the right so that the newly summoned entourage is placed in the POS position theplayer[who][i] = player[who][i-1]; the         } -Player[who][pos].attack = att;//assign attack and blood to the summoned companion inPlayer[who][pos].health =hea; the     } the      about } the  the voidDeleteintwho,intPOS) the{//to remove the dead Entourage. +     inti; -     if(pos >0)//only the entourage needs to be removed . the     {Bayi          for(i = pos; I < role_num[who]; i + +) the{//Remove the attendant at the Pos location, and the attendant on the right side of the POS will move one position to the left theplayer[who][i] = player[who][i+1]; -         } -role_num[who]--;//after removing an entourage, the number of roles is reduced by 1 the     } the } the  the voidAttackintwho,intpos1,intPos2) -{//attack function theplayer[who][pos1].health-= player[1-who][pos2].attack;//the reduced value of the attacker's blood is equal to the Attacker's attack Value. theplayer[1-who][pos2].health-= player[who][pos1].attack;//attack each other at the same time, they will be affected by each Other's attack size of the blood volume the     if(player[who][pos1].health <=0)//after the attendant blood amount is less than or equal to 0, the removal94 Delete (who, pos1); the     if(player[1-who][pos2].health <=0) theDelete1-who , pos2); the}

The Legend of CCF2016093 Furnace stone (c language Edition)

Related Article

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.