2023CCPC女生专场 G-精灵宝可梦对战

2023CCPC女生专场 G-精灵宝可梦对战

难度: ☀️

类型: 模拟,STL

题意: 题目链接

解题思路:

由规则2、3、4、可知,精灵对战的顺序可以用队列来模拟实现。用结构体记录精灵的各项数值。按照规则进行模拟。

以下是完整代码

#include<iostream>
#include<map>
#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>

using namespace std;


struct BB {
  int h, a, b, c, d, e, w; // 记录精灵的各种属性
  int E = 0; // 记录精灵当前的能量
}A, B;

int n, m, k;
int main() {
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin >> n >> m >> k;
  queue<BB> AA;
  queue<BB> BB; // 用两个队列模拟两人的精灵队列
  for (int i = 0; i < n; i++) {
    cin >> A.h >> A.a >> A.b >> A.c >> A.d >> A.e >> A.w;
    AA.push(A);

  }
  for (int i = 0; i < m; i++) {
    cin >> B.h >> B.a >> B.b >> B.c >> B.d >> B.e >> B.w;
    BB.push(B);
  }
  int flag = 0; //用flag来记录两人的胜负;
  while (k--) { // 对战k场
    int a = AA.front().a - BB.front().c; // 小A的精灵先攻击
    a = a > 0 ? a : 0; // 计算物理造成的伤害
    int b = AA.front().b - BB.front().d;
    b = b > 0 ? b : 0; // 计算魔法造成的伤害;
    int w = 0; // 计算大招伤害
    if (AA.front().E >= AA.front().e) { w = AA.front().w; }// 能量足够则可以释放大招
    if (a >= w && a >= b) { //此为物伤最高时。如果伤害相等,优先级:物伤=法伤>大招
      BB.front().h -= a;
      if (BB.front().h <= 0) BB.pop(); // 若剩余血量不足1,就弹出
      AA.front().E++;// 每次普攻,能量+1
      AA.push(AA.front()); AA.pop(); // 攻击之后排到队尾
      if (BB.empty()) flag = 1;
    }
    else if (b >= w && b >= a) { 
      BB.front().h -= b;
      if (BB.front().h <= 0) BB.pop(); 
      AA.front().E++;
      AA.push(AA.front()); AA.pop();
      if (BB.empty()) flag = 1;
    }
    else { // 大招伤害最高时
      BB.front().h -= w;
      if (BB.front().h <= 0) BB.pop();
      AA.front().E -= AA.front().e; // 使用大招消耗能量
      AA.push(AA.front()); AA.pop();
      if (BB.empty()) flag = 1;
    }
    if (flag) break; // 有一人的精灵全部阵亡
    // 小A攻击之后,小B攻击,重复过程
    a = BB.front().a - AA.front().c; 
    a = a > 0 ? a : 0; 
    b = BB.front().b - AA.front().d;
    b = b > 0 ? b : 0; 
    w = 0; 
    if (BB.front().E >= BB.front().e) { w = BB.front().w; }
    if (a >= w && a >= b) { 
      AA.front().h -= a;
      if (AA.front().h <= 0) AA.pop(); 
      BB.front().E++;
      BB.push(BB.front()); BB.pop();
      if (AA.empty()) flag = 2;
    }
    else if (b >= w && b >= a) {
      AA.front().h -= b;
      if (AA.front().h <= 0) AA.pop();
      BB.front().E++;
      BB.push(BB.front()); BB.pop();
      if (AA.empty()) flag = 2;
    }
    else { 
      AA.front().h -= w;
      if (AA.front().h <= 0) AA.pop();
      BB.front().E -= BB.front().e; 
      BB.push(BB.front()); BB.pop();
      if (AA.empty()) flag = 2;
    }
    if (flag) break;
  }
  if (flag == 0) cout << "Draw\n";
  else if (flag == 1) cout << "Alice\n";
  else if (flag == 2) cout << "Bob\n";
  return 0;
}
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值