当前位置:网站首页>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 !️️️️
边栏推荐
- QPushButton 样式使用示例(以及按钮setmenu添加下拉菜单的方法)
- Deployment and operation of mongodb partitioned cluster
- Swap two numbers
- Platform management background and merchant menu resource management: Design of platform management background data service
- Decentralized NFT transaction protocol will defeat opensea
- Strength and appearance Coexist -- an exclusive interview with Liu Yu, a member of Apache pulsar PMC
- When I was in the library, I thought of the yuan sharing mode
- Find out the maximum value of each column element of NxN matrix and store it in the one-dimensional array indicated by formal parameter B in order
- Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
- Teach you to learn dapr - 6 Publish subscription
猜你喜欢

关于FlowUs这一款国民好笔记

How sparksql returns a specific day of the week by date -dayofweek function

Cache breakdown! Don't even know how to write code???
![[ten thousand words summary] starting from the end, analyze in detail how to fill in the college entrance examination volunteers](/img/77/715454c8203d722e246ed70e1fe0d8.png)
[ten thousand words summary] starting from the end, analyze in detail how to fill in the college entrance examination volunteers

Platform management background and merchant menu resource management: merchant registration management design

MySQL add column failed because there was data before, not null by default

Alibaba's "high concurrency" tutorial "basic + actual combat + source code + interview + Architecture" is a god class

Kubernetes essential tools: 2021

SIGIR 2022 | 港大等提出超图对比学习在推荐系统中的应用
![[recommendation system learning] technology stack of recommendation system](/img/ff/afc6f4b0997cfcb9e01ffbebf2a872.png)
[recommendation system learning] technology stack of recommendation system
随机推荐
Leetcode topic [array] -283- move zero
[dynamic planning] Jianzhi offer II 091 Paint the house
牛客网:设计LRU缓存结构 设计LFU缓存结构
Romance of the Three Kingdoms: responsibility chain model
NFT 交易市场社区所有化势不可挡
【uniapp】uniapp手机端使用uni.navigateBack失效问题解决
一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
Environment setup mongodb
Viteconfigure project path alias
QPushButton 样式使用示例(以及按钮setmenu添加下拉菜单的方法)
Calculate the average of N numbers in the group indexed by the formal parameter x, move the data less than the average in the group indexed to the front of the array, and move the data greater than or
Byte interview: two array interview questions, please accept
Jouer avec Linux et installer et configurer MySQL facilement
用redis做用户访问数据统计HyperLogLog及Bitmap高级数据类型
[qt learning notes]qt inter thread data communication and data sharing
sparksql如何通过日期返回具体周几-dayofweek函数
分布式架构概述
【万字总结】以终为始,详细分析高考志愿该怎么填
MySQL index
合约量化系统开发方案详细,量化合约系统开发技术说明