当前位置:网站首页>一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
一起备战蓝桥杯与CCF-CSP之大模拟炉石传说
2022-06-26 16:53:00 【工藤学编程】
大家好,这是一起备战CCF与蓝桥杯系列第3篇,之前因为考试周的原因好久没更了,继续开始我们的备战之旅!!!
之前我们已经讲解了我们的备战思路以及一些题目,大家忘记了可以去看看哦!!
1.备战思路及大模拟模板生成系统
2.一起备战蓝桥杯与CCF-CSP之大模拟画图)
3.一起备战蓝桥杯与CCF-CSP之大模拟路径解析
什么,你作业很多?快来看看作业侠系列的最新文章有没有你需要的吧!
作业侠最新文章
话不多说,开始今天的题目讲解,这次我们要模拟的是炉石传说!

具体题目如下(图片来源:ACwing):

官网对应链接:
先说刷题感想:
相比以前,要是我看到这又丑又长的题目,早跑路了,但是刷了几题之后,感觉这确实没啥,在自己能够理解的范围,要实现也不是很难,只要会基础的一些语法就能够解出来的,所以希望大家坚持下去,我们一起坚持!!!
解题思路:
首先我们需要想好怎么存储题目中涉及的数据,y总说过,大模拟只要想好怎么存储,其他的问题都问题不大,根据题目要求,
我们需要存储的数据有:
1.双方英雄的生命值和攻击力
2.双方随从的生命值和攻击力
需要我们解决的问题有:
1.回合制如何切换?
2.随从召唤需要移动位置如何处理?
3.随从死亡左移如何处理?
上面的问题如何解决,见下面代码里的注释
代码如下(不正确版,反面教材,不过思路没问题):
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct Role{
int attack;
int hp;
}role[2][10];
/**1.解决如何存储问题 我们可以考虑使用一个二维结构体数组role来存储,结构体元素有hp(生命 值),attack(攻击力),第一维用于表示双方,且我们可以考虑, 使用role[0][0],role[1][0]来分别用于存储双方英雄的相应信息, 同样的,对应二维下标一次就用来表示随从,第二位开到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;
/** 解决问题1.如何切换回合制,用一个变量每结束一次++,然后用他%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};
/**解决问题2. 如果我们直接考虑正向移动,比较麻烦, 但是如果我们考虑直接从后面移动,就会变的非常简单!!, 因为题目数据会保证任意时刻随从数量小于7(在召唤随从的时候), 于是我们从7开始,每次往后赋值即可, 最后,直接将需要召唤的位置赋值给召唤的随从即可! **/
}
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];
/** 解决问题3. 如果随从死亡,我们需要将他后面的随从依此左移,因为随从已经死亡了, 所以我们从后往前依此覆盖一位即可, 有小伙伴可能会疑惑他移动后的最后一个随从的值怎么从新初始化的,因为 我们的role[l][8]一直都是未初始化,所以for(int i=y;i<=7;i++) role[!l][y]=role[!l][y+1];,这样就能初始化最后一位为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;
}
上面的代码问题在于博主没有认真看题,他应该是被攻击的hp-攻击的attack,并且在, 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];
上面的role[l][x]应该改为对应的y,cv之后忘记改了,不过我为大家交了一发试试水,就这lj代码Acwing能过5个点,官网能过50%,这还不快来和我一起刷,血赚!
下面是正确代码:
#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交,wa的是前一个代码的
官网交:
最后是y总代码:
#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;
}
作者:yxc
链接:https://www.acwing.com/activity/content/code/content/875258/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
只能说y总nb,今天就到这里吧!️️️️
边栏推荐
- 经典同步问题
- Jouer avec Linux et installer et configurer MySQL facilement
- Romance of the Three Kingdoms: responsibility chain model
- Swap two numbers
- Interpretation of new plug-ins | how to enhance authentication capability with forward auth
- 链游系统开发技术方案设计丨NFT链游系统开发流程及源码
- The function keeps the value of variable H to two decimal places and rounds the third digit
- [recommendation system learning] recommendation system architecture
- Summary of all knowledge points of C language
- Army chat -- registration of Registration Center
猜你喜欢

NFT 交易市场社区所有化势不可挡

Romance of the Three Kingdoms: responsibility chain model

Kubecon China 2021 Alibaba cloud special session is coming! These first day highlights should not be missed

7 views on NFT market prospect

R329 (maix-ii-a (M2A) data summary

去中心化NFT交易协议将击败OpenSea

Community ownership of NFT trading market is unstoppable

Redis and database data consistency

Sandboxed container: container or virtual machine

In those years, interview the abused red and black trees
随机推荐
Vue--vuerouter cache routing component
Can Luo Yonghao succeed in entering the AR field this time?
COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
Calculate the average of N numbers in the index group of X, and return the number that is less than the average and closest to the average through formal parameters
[Error] ld returned 1 exit status
Over the weekend: 20000 words! Summary of JVM core knowledge, 18 serial cannons as a gift
分布式缓存/缓存集群简介
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
Microservice architecture practice: user login and account switching design, order query design of the mall
Secrets of gear contract
C语言所有知识点小结
Overall context of concurrent programming
宝藏又小众的CTA动画素材素材网站分享
Day10 daily 3 questions (1): sum gradually to get the minimum value of positive numbers
【推荐系统学习】推荐系统的技术栈
ACL 2022 | zero sample multilingual extracted text summarization based on neural label search
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Use FST JSON to automatically generate faster JSON serialization methods
Sandboxed container: container or virtual machine
Teach you to learn dapr - 1 The era of net developers