SDU monthly simulation question CSP201609-3 legend of furnace stone

Problem description Hearthstone: Heroes of Warcraft is an integrated card game developed by Blizzard Entertainment (as s...

Problem description
Hearthstone: Heroes of Warcraft is an integrated card game developed by Blizzard Entertainment (as shown below).

The game is played on a battle board by two players in turn. The simplified rules of the game are as follows:

*Players will control some characters. Each character has its own health and attack power. When the health value is less than or equal to 0, the character dies. The characters are divided into hero and follower.
* each player controls a hero. At the beginning of the game, the hero's HP is 30 and attack power is 0. When the hero dies, the game is over and the undead side of the hero wins.
* players can call their followers during the game. On the chessboard, each side has seven spaces for the attendants, which are arranged from left to right. It is called the battlefield. When the retinue dies, it will be removed from the battlefield.
* after the start of the game, two players take turns to operate. Each player's successive group of operations is called a round.
* in each round, the current player can perform zero or more of the following operations:
1) summon follower: players summon a follower to enter the battlefield, and the follower has the specified life value and attack power.
2) follower attack: the player controls one of his followers to attack the hero or follower of the opponent.
3) end round: the player declares that his current round is over and the game will enter the opponent's round. This operation must be the last operation of a round.
* when the follower attacks, the attacker and the victim will cause damage equal to their own attack power to each other at the same time. The damaged character's health will be reduced, equal to the damage taken. For example, the HP of follower X is HX, the attack power is AX, the HP of follower Y is HY, and the attack power is AY. If follower X attacks follower Y, the HP of follower X changes to hx-AY and the HP of follower Y changes to HY-AX after the attack. After an attack, the character's health can be negative.
This topic will give a game process, which requires programming to simulate the game process and output the final situation.
Input format
The first input line is an integer n, which represents the number of operations. Next, there are n lines. Each line describes an operation. The format is as follows:
...
There are three types of operation types, which are a string: sum for calling follower, attack for follower attack and end for ending round. The specific formats of these three operations are as follows:
* summer: the current player summons a follower with HP and attack power at the position. Where is an integer from 1 to 7, indicating the position of the summoned follower on the battlefield. The original position and the follower on the right will move one bit to the right in sequence.
* attack: the character of the current player attacks the character of the opponent. It is an integer from 1 to 7, indicating the number of our party's follower who launched the attack, an integer from 0 to 7, indicating the role of the attacked opponent, 0 indicating the hero who attacked the opponent, and 1 to 7 indicating the number of the follower who attacked the opponent.
* end: the current player ends this round.
Note: the number of retinues will change with the process of the game. When a retinue is called, the player specifies the location where the retinue is called into the battlefield. At this time, the number of the original location and all retinues on the right will be increased by 1. When a retinue dies, all the retinue numbers on its right decrease by 1. At any time, the followers on the battlefield are always numbered consecutively from 1.
Output format
Output 5 lines in total.
The first line contains an integer indicating the outcome of the game after n operations (hereinafter referred to as "T moment"), 1 indicating that the first player wins, 1 indicating that the second player wins, 0 indicating that the game is not over and no one has won.
Line 2 contains an integer that represents the life of the hero of the first player at time T.
The third line contains several integers. The first integer P represents the number of followers that the first player survives on the battlefield at time T, and then p integers represent the life values of these followers at time T (in the order from left to right).
Lines 4 and 5 are similar to lines 2 and 3, except that they change players from the first player to the second player.

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 //sample output 0 30 1 2 30 1 2

Sample description
Following the example input, explain line by line from line 2 as follows:
1. The first player summons A follower A with A HP of 6 and an attack power of 3 at position 1, which is the only follower on our battlefield.
2. The first player summons A follower B in position 2 with A health value of 2 and an attack power of 4, which appears on the right side of follower A.
3. The first player's turn ends.
4. The backhand player summons a follower C with a HP of 5 and an attack power of 4 at position 1, which is the only follower on our battlefield.
5. In position 1, the backhand player summons a follower D with a HP of 1 and an attack power of 2, which appears on the left side of follower C.
6. Follower D attacks follower B, both sides are dead.
7. The backhand player's turn ends.
8. Follower A attacks follower C, and the health value of both sides is reduced to 2.
Scale and convention of evaluation case
* number of operations 0 ≤ n ≤ 1000.
* the follower's initial health value is an integer from 1 to 100, and the attack power is an integer from 0 to 100.
* ensure that all operations are legal, including but not limited to:
1) the location of the summoned follower must be legal, that is, if there are m followers on the current battlefield, the location of the summoned follower must be between 1 and 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 our battlefield, no new followers will be called.
3) there must be roles to attack and be attacked, and the attacking role's attack power is greater than 0.
4) if a hero dies, there will be no follow-up operations.
* data conventions:
The first 20% of evaluation cases call their followers to the far right of the battlefield.
The first 40% of the evaluation cases have no attack operation.
The first 60% of the evaluation cases will not be accompanied by death.

Idea: this topic is relatively simple. There are two kinds of structure questions, follower and player. Each behavior is encapsulated into a method. There is not too much pit, even if you have played with the furnace stone, you hardly need to read (escape)

// // Created by haofeng on 4/27/20. // #include <iostream> #include <vector> #include <string> using namespace std; int nowPlayer=0;//Which player is currently playing string cmd; int n; struct summon{ int attack=0; int health=0; bool death=false; summon(){}; summon(int attack,int health){ this->attack=attack; this->health=health; } void att2sum(summon& sum){ //this attack that sum.health-=this->attack; this->health-=sum.attack; //Determine if you are dead if(sum.health<=0)sum.death= true; if(this->health<=0)this->death=true; } }; struct players{ summon SUMM[10];//entourage bool haveSU[10];// int health=30; players(){ SUMM[8]; haveSU[8]; for (int i = 0; i < 10; ++i) haveSU[i]=false; } void addsummon(summon su,int pos); void clearsummon(); }; void players::clearsummon(){ for (int i = 1; i <=7 ; ++i) { if(haveSU[i]&&SUMM[i].death){ //Move left for (int j = i; j <=7 ; ++j) { //Change presence and entourage haveSU[j]=haveSU[j+1]; SUMM[j]=SUMM[j+1]; } } } for (int i = 1; i <=7 ; ++i) { if(SUMM[i].health<=0)haveSU[i]=false; } } void players::addsummon(summon su,int pos) { if(this->haveSU[pos]=true){ //Move first for (int i = 6; i >=pos ; --i) { //I'm sure I can, so there's a maximum of six if(haveSU[i]){ SUMM[i+1]=SUMM[i]; haveSU[i+1]=haveSU[i]; } } } SUMM[pos]=su; } players PLAYS[2]; int main(){ cin>>n; summon su; int pos; int attfrom,attto; for (int i = 0; i <n ; ++i) { cin>>cmd; if(cmd=="summon"){ cin>>pos>>su.attack>>su.health; PLAYS[nowPlayer].addsummon(su,pos); } if(cmd=="end"){ nowPlayer^=1; } if(cmd=="attack"){ cin>>attfrom>>attto; if(attto==0)PLAYS[nowPlayer^1].health-=PLAYS[nowPlayer].SUMM[attfrom].attack; else{PLAYS[nowPlayer].SUMM[attfrom].att2sum(PLAYS[nowPlayer^1].SUMM[attto]);} } PLAYS[nowPlayer].clearsummon(); PLAYS[nowPlayer^1].clearsummon(); } if(PLAYS[0].health>0&&PLAYS[1].health<=0)cout<<1<<endl; else if(PLAYS[0].health<=0&&PLAYS[1].health>0)cout<<-1<<endl; else cout<<0<<endl; cout<<PLAYS[0].health<<endl; vector<int> sv; for (int i = 1; i <=7 ; ++i) { if(PLAYS[0].haveSU[i])sv.push_back(PLAYS[0].SUMM[i].health); } cout<<sv.size(); for (int i = 0; i <sv.size() ; ++i) { cout<<" "<<sv[i]; } cout<<endl; sv.clear(); cout<<PLAYS[1].health<<endl; for (int i = 1; i <=7 ; ++i) { if(PLAYS[1].haveSU[i])sv.push_back(PLAYS[1].SUMM[i].health); } cout<<sv.size(); for (int i = 0; i <sv.size() ; ++i) { cout<<" "<<sv[i]; } }

Conclusion: joining and dying is a little more complicated. Other things are really direct

7 June 2020, 00:40 | Views: 5972

Add new comment

For adding a comment, please log in
or create account

0 comments