当前位置:网站首页>Preparing for the Blue Bridge Cup and ccf-csp

Preparing for the Blue Bridge Cup and ccf-csp

2022-06-26 17:23:00 Kudo programming

Hello everyone , This is preparing for war CCF With the Blue Bridge Cup Series No 3 piece , I haven't changed for a long time because of the exam week , Continue to start our preparation journey !!!

We have already explained our War preparation ideas and some topics , If you forget, you can go and have a look !!
1. War preparation ideas and large simulation template generation system
2. Prepare for the Blue Bridge Cup and CCF-CSP The big simulation drawing )
3. Prepare for the Blue Bridge Cup and CCF-CSP Large simulation path analysis

what , You have a lot of homework ? Come and have a look Homework series Is there anything you need in the latest article of !
Homework man's latest article

Don't talk much , Start today's topic , This time we are going to simulate the legend of hearthstone !

 Please add a picture description

The specific topics are as follows ( picture source :ACwing):

 Insert picture description here
Corresponding links on the official website :

BFS legend

First, let's talk about the feeling of brushing questions :

Compared with before , If I see this ugly and long topic , I've already run away , But after a few questions , It doesn't really matter , To the extent that you can understand , It is not very difficult to realize , As long as you know some basic grammar, you can solve it , So I hope you will stick to it , Let's stick to !!!

Their thinking :

First, we need to figure out how to store the data involved in the topic ,y Always said , As long as you figure out how to store the big simulation , Other problems are not big problems , According to the title requirements ,
The data we need to store are :
1. Health and attack power of heroes on both sides
2. HP and attack power of both followers
The problems we need to solve are :
1. How to switch round system ?
2. How to deal with the situation when the attendant needs to move ?
3. How to deal with the death of the entourage ?

How to solve the above problems , See the comments in the code below

The code is as follows ( Incorrect version , Cautionary tale , But the idea is OK ):

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Role{
    
    int attack;
    int hp;
}role[2][10];
/**1. Solve the problem of how to store   We can consider using a two-dimensional array of structures role To store , The structure elements have hp( life   value ),attack( aggressivity ), The first dimension is used to represent both sides , And we can consider ,  Use role[0][0],role[1][0] To store the corresponding information of the heroes of both sides ,  alike , The corresponding two-dimensional subscript is used once to represent the follower , The second place opens to 10 The function of is not just to prevent subscripts from crossing the bounds , There are also functions behind it ! **/
int t=0;
int l=0;

int main()
{
    
    role[0][0]=role[1][0]={
    0,30};
    int n;
    cin>>n;
    while(n--)
    {
    
        string s;
        cin>>s;
        if(s=="end")
        {
    
            t++;
            l=t%2;
            /**  solve the problem 1. How to switch round system , End each time with a variable ++, Then use him %2 that will do  **/
        }
        else if(s=="summon")
        {
    
            int x,y,z;
            cin>>x>>y>>z;
            for(int i=7;i>x;i--) role[l][i]=role[l][i-1];
            role[l][x]={
    y,z};
            /** solve the problem 2.  If we directly consider forward movement , More trouble ,  But if we consider moving directly from the back , It will become very simple !!,  Because the subject data will ensure that the number of followers at any time is less than 7( When summoning an attendant ),  So we started with 7 Start , Each subsequent assignment is sufficient ,  Last , Directly assign the position to be summoned to the summoned follower ! **/
        }
        else
        {
    
            int x,y;
            cin>>x>>y;
            role[!l][y].hp=role[l][x].attack-role[!l][y].hp;
            role[l][x].hp=role[!l][y].attack-role[l][x].hp;
            if(role[l][x].hp<=0 && x) for(int i=x;i<=7;i++) role[l][x]=role[l][x+1];
            if(role[!l][y].hp<=0 && y!=0) for(int i=y;i<=7;i++) role[!l][y]=role[!l][y+1];
            /**  solve the problem 3.  If the follower dies , We need to move his followers to the left , Because the entourage is dead ,  So we can cover one bit from the back to the front ,  A little friend may wonder how the value of the last follower after he moves is initialized again , because   our role[l][8] Always uninitialized , therefore for(int i=y;i<=7;i++) role[!l][y]=role[!l][y+1];, This initializes the last bit to 0 了 ! **/
        }
    }
    if(role[0][0].hp<=0) puts("-1");
    else if(role[1][0].hp<=0) puts("1");
    else puts("0");
    cout<<role[0][0].hp<<endl;
    int live=0;
    for(int i=1;i<=7;i++)
    {
    
        if(role[0][i].hp>0) live++;
    }
    cout<<live<<" ";
    for(int i=1;i<=7;i++)
    {
    
        if(role[0][i].hp > 0) cout<<role[0][i].hp<<" ";
    }
    cout<<endl;
    cout<<role[1][0].hp<<endl;
     int live1=0;
    for(int i=1;i<=7;i++)
    {
    
        if(role[1][i].hp>0) live1++;
    }
    cout<<live1<<" ";
    for(int i=1;i<=7;i++)
    {
    
        if(role[1][i].hp>0) cout<<role[1][i].hp<<" ";
    }
    cout<<endl;
    return 0;
}

The problem with the above code is that the blogger didn't take the title seriously , He should have been attacked hp- The attack attack, And in , if(role[l][x].hp<=0 && x) for(int i=x;i<=7;i++) role[l][x]=role[l][x+1];
if(role[!l][y].hp<=0 && y!=0) for(int i=y;i<=7;i++) role[!l][y]=role[!l][y+1];
above role[l][x] It should be changed to the corresponding y,cv Then I forgot to change , But I gave you a test of water , Is this lj Code Acwing Yes 5 A little bit , On the official website 50%, Come and brush with me , Blood earned !

Here is the correct code :

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Role{
    
    int attack;
    int hp;
}role[2][10];
int t=0;
int l=0;

int main()
{
    
    role[0][0]=role[1][0]={
    0,30};
    int n;
    cin>>n;
    while(n--)
    {
    
        string s;
        cin>>s;
        if(s=="end")
        {
    
            t++;
            l=t%2;
        }
        else if(s=="summon")
        {
    
            int x,y,z;
            cin>>x>>y>>z;
            for(int i=7;i>x;i--) role[l][i]=role[l][i-1];
            role[l][x]={
    y,z};
            
        }
        else
        {
    
            int x,y;
            cin>>x>>y;
            role[!l][y].hp=role[!l][y].hp-role[l][x].attack;
            role[l][x].hp=role[l][x].hp-role[!l][y].attack;
            // cout<<role[!l][y].hp<<endl;
            if(role[l][x].hp<=0 && x) for(int i=x;i<=7;i++) role[l][i]=role[l][i+1];
            if(role[!l][y].hp<=0 && y) for(int i=y;i<=7;i++) role[!l][i]=role[!l][i+1];
        }
    }
    if(role[0][0].hp<=0) puts("-1");
    else if(role[1][0].hp<=0) puts("1");
    else puts("0");
    cout<<role[0][0].hp<<endl;
    int live=0;
    for(int i=1;i<=7;i++)
    {
    
        if(role[0][i].hp>0) live++;
    }
    cout<<live<<" ";
    for(int i=1;i<=7;i++)
    {
    
        if(role[0][i].hp > 0) cout<<role[0][i].hp<<" ";
    }
    cout<<endl;
    cout<<role[1][0].hp<<endl;
     int live1=0;
    for(int i=1;i<=7;i++)
    {
    
        if(role[1][i].hp>0) live1++;
    }
    cout<<live1<<" ";
    for(int i=1;i<=7;i++)
    {
    
        if(role[1][i].hp>0) cout<<role[1][i].hp<<" ";
    }
    cout<<endl;
    return 0;
}

Acwing hand over ,wa Of the previous code
 Insert picture description here The official website :
 Insert picture description here And finally y Master code :

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

struct Role
{
    
    int a, h;
}p[2][10];

void remove(int k, int pos)
{
    
    for (int i = pos; i <= 7; i ++ )
        p[k][i] = p[k][i + 1];
}

int main()
{
    
    int n;
    cin >> n;

    p[0][0].h = p[1][0].h = 30;

    int k = 0;
    while (n -- )
    {
    
        string op;
        cin >> op;
        if (op == "end") k ^= 1;
        else if (op == "summon")
        {
    
            int pos, a, h;
            cin >> pos >> a >> h;
            for (int i = 7; i > pos; i -- ) p[k][i] = p[k][i - 1];
            p[k][pos] = {
    a, h};
        }
        else
        {
    
            int a, d;
            cin >> a >> d;
            p[k][a].h -= p[!k][d].a;
            p[!k][d].h -= p[k][a].a;
            if (a && p[k][a].h <= 0) remove(k, a);
            if (d && p[!k][d].h <= 0) remove(!k, d);
        }
    }

    if (p[0][0].h <= 0) puts("-1");
    else if (p[1][0].h <= 0) puts("1");
    else puts("0");

    for (int k = 0; k < 2; k ++ )
    {
    
        cout << p[k][0].h << endl;
        int s = 0;
        for (int i = 1; i <= 7; i ++ )
            if (p[k][i].h > 0)
                s ++ ;
        cout << s << ' ';
        for (int i = 1; i <= s; i ++ )
            cout << p[k][i].h << ' ';
        cout << endl;
    }

    return 0;
}

 author :yxc
 link :https://www.acwing.com/activity/content/code/content/875258/
 source :AcWing
 The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .

It can only be said y total nb, Come here today !️️️️

原网站

版权声明
本文为[Kudo programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206261651539132.html