当前位置:网站首页>一起备战蓝桥杯与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,今天就到这里吧!️️️️
边栏推荐
- Detailed explanation of browser storage methods: the origin and difference of cookies, localstorage and sessionstorage
- Constructors and Destructors
- 探讨:下一代稳定币
- SIGIR 2022 | University of Hong Kong and others proposed the application of hypergraph comparative learning in Recommendation System
- [latex bearer] use tables in \title (error \begin doesn't match its definition.)
- Call the random function to generate 20 different integers and put them in the index group of institute a
- C语言所有知识点小结
- Technical scheme design of chain game system development - NFT chain game system development process and source code
- 链游系统开发技术方案设计丨NFT链游系统开发流程及源码
- Introduction to minimal API
猜你喜欢

Leetcode 1169. 查询无效交易(如果数据量不大,这种题还是得暴力枚举解决)

Interpretation of new plug-ins | how to enhance authentication capability with forward auth

SIGIR 2022 | University of Hong Kong and others proposed the application of hypergraph comparative learning in Recommendation System

SQL injection for Web Security (3)

Interpretation of cloud native microservice technology trend

Distributed Architecture Overview

Summary of all knowledge points of C language

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

防火 疏散 自救…这场安全生产暨消防培训干货满满!

A simple membership card management system based on Scala
随机推荐
链游系统开发技术方案设计丨NFT链游系统开发流程及源码
Redis 概述整理
Programmer interview guide - self introduction
Stm32f103c8t6 realize breathing lamp code
Distributed Architecture Overview
Interpretation of cloud native microservice technology trend
Programmer's essential toolkit, please collect!
7 views on NFT market prospect
Call the random function to generate 20 different integers and put them in the index group of institute a
Army chat -- registration of Registration Center
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
[Error] ld returned 1 exit status
Use middleware to record slow laravel requests
Demonstrate to Xiaobai the case of sub database and sub table
Platform management background and merchant menu resource management: merchant registration management design
Leetcode 1169. Query invalid transactions (if the amount of data is small, this problem still needs to be solved by violent enumeration)
进军AR领域,这一次罗永浩能成吗?
Day10 daily 3 questions (2): count the number of the largest groups
Getting started with mongodb
Teach you to learn dapr - 5 Status management