当前位置:网站首页>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 !

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

Corresponding links on the official website :
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
The official website :
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 !️️️️
边栏推荐
- Use FST JSON to automatically generate faster JSON serialization methods
- 20:第三章:开发通行证服务:3:在程序中,打通redis服务器;(仅仅是打通redis服务器,不涉及具体的业务开发)
- mysql Add column 失败 因为之前有数据,不是默认null 不行
- Teach you to learn dapr - 5 Status management
- Technical scheme design of chain game system development - NFT chain game system development process and source code
- [code Capriccio - dynamic planning] t583. Deleting two strings
- sparksql如何通过日期返回具体周几-dayofweek函数
- Cache breakdown! Don't even know how to write code???
- [C language] static modifies local variables
- Byte interview: two array interview questions, please accept
猜你喜欢

Web3 decentralized storage ecological landscape

Introduction to distributed cache / cache cluster

【代码随想录-动态规划】T583、两个字符串的删除操作

Niuke network: Design LRU cache structure design LFU cache structure

Deployment and operation of mongodb partitioned cluster

The latest masterpiece of Alibaba, which took 182 days to produce 1015 pages of distributed full stack manual, is so delicious

宝藏又小众的CTA动画素材素材网站分享

Redis' 43 serial cannons, try how many you can carry

数字藏品与NFT到底有何区别

The difference between round and truncate in SQL (round or truncate)
随机推荐
Leetcode topic [array] -268- missing numbers
Community ownership of NFT trading market is unstoppable
Prometeus 2.34.0 new features
Deployment and operation of mongodb partitioned cluster
Teach you to learn dapr - 6 Publish subscription
Calculate the sum of the main diagonals of the array
Notes on flowus
Incomplete line spacing adjustment of formula display in word
What does the equals method compare? Who told you
Inspirational. In one year, from Xiaobai to entering the core Department of Alibaba, his counter attack
14 MySQL tutorial insert insert data
防火 疏散 自救…这场安全生产暨消防培训干货满满!
Platform management background and merchant menu resource management: access control design of platform management background
A simple membership card management system based on Scala
有依赖的背包问题
Problems encountered this week
一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
Uncover the secret of Agora lipsync Technology: driving portraits to simulate human speech through real-time voice
Army chat -- registration of Registration Center
Use middleware to record slow laravel requests