0分求调/kel
查看原帖
0分求调/kel
376161
Phartial啊?楼主2021/9/25 18:57

rt,第一个样例能过,第二个样例不知道为啥卡死了,有神仙能帮忙看一下吗

因为本人电脑太烂了没法调试所以只能发帖

#include <iostream>

using namespace std;
using E = struct { int t, v; };

const int kN = 31;
const int kK = 3e5 + 1;
const string kS[8] = {"C", "A", "B", "D", "E", "PASS", "TURN", "DOUBLE"};

struct P {
  string s;
  E p[3];
} a[kN];

int n, m, k, p, t;
E e[kK];

E G() {
  string s;
  cin >> s;
  // printf("[DEBUG] The Card is %s\n", s.c_str());
  E x;
  if (s[0] == 'C') {
    x = {0, 2};
  } else if (s[0] == 'A') {
    x = {1, s.size() == 2 ? s[1] - '0' : s[1] * 10 + s[2] - '0' * 11};
  } else if (s[0] == 'B') {
    x = {2, s.size() == 2 ? s[1] - '0' : s[1] * 10 + s[2] - '0' * 11};
  } else if (s[0] == 'D') {
    x = {s[1] == 'O' ? 7 : 3, 2};
  } else if (s[0] == 'E') {
    x = {4, s.size() == 2 ? s[1] - '0' : s[1] * 10 + s[2] - '0' * 11};
  } else {
    x.t = (s == "PASS" ? 5 : 6);
  }
  // printf("[DEBUG] Translate (%d,%d)\n", x.t, x.v);
  return x;
}

int F(E x) {
  if (x.t == 0) {
    return p << 1;
  } else if (x.t == 1) {
    return p + x.v;
  } else if (x.t == 2) {
    return p - x.v;
  } else if (x.t == 3) {
    return p >> 1;
  } else {
    return x.v;
  }
}

int main() {
  freopen("P7506.in", "r", stdin);
  freopen("P7506.out", "w", stdout);
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    // printf("[DEBUG] Reading Player %d\n", i);
    cin >> a[i].s;
    for (int j = 0; j < 3; ++j) {
      // printf("[DEBUG]   Reading Card %d\n", j);
      a[i].p[j] = G();
    }
  }
  for (int i = 1; i <= k; ++i) {
    // printf("[DEBUG] Reading Card %d\n", i);
    e[i] = G();
  }
  // printf("[DEBUG] Reading End\n");
  for (int _ = 1, o = 0; _ <= m; ++_) {
    printf("Round %d:\n", _);
    p = 0;
    for (int d = 1, f = 0;; o = (o + d) % n) {
      // printf("[DEBUG] %d %s (%d,%d) (%d,%d) (%d,%d)\n", o, a[o].s.c_str(), a[o].p[0].t, a[o].p[0].v, a[o].p[1].t, a[o].p[1].v, a[o].p[2].t, a[o].p[2].v);
      if (f) {
        bool _f = 0;
        for (int i = 5; i <= 7; ++i) {
          for (int j = 0; j < 3; ++j) {
            if (a[o].p[j].t == i) {
              a[o].p[j] = e[++t], i == 6 && (d = -d), _f = 1;
              printf("%s used %s,now p=%d.\n", a[o].s.c_str(), kS[i].c_str(), p);
              break;
            }
          }
          if (_f) {
            break;
          }
        }
        if (_f) {
          continue;
        }
        int _p = F(a[o].p[0]), _i = 0;
        for (int i = 1; i < 3; ++i) {
          if (F(a[o].p[i]) < _p) {
            _p = F(a[o].p[i]), _i = i;
          } else if (F(a[o].p[i]) == _p) {
            if ((a[o].p[i].t == 4 ? -1 : a[o].p[i].t) > (a[o].p[_i].t == 4 ? -1 : a[o].p[_i].t)) {
              _i = i;
            }
          }
        }
        if ((p = _p) > 99) {
          printf("%s lost the game.\n", a[o].s.c_str());
          a[o].p[0] = e[++t], a[o].p[1] = e[++t], a[o].p[2] = e[++t];
          break;
        }
        printf("%s used %s%d,now p=%d.\n", a[o].s.c_str(), kS[a[o].p[_i].t].c_str(), a[o].p[_i].v, p);
        f = 0, a[o].p[_i] = e[++t];
      }
      int _p = -100000, _i = -1;
      for (int i = 0; i < 3; ++i) {
        if (a[o].p[i].t < 5) {
          if (F(a[o].p[i]) > _p && F(a[o].p[i]) <= 99) {
            _p = F(a[o].p[i]), _i = i;
          } else if (F(a[o].p[i]) == _p) {
            if (_i == -1 || a[o].p[i].t < a[o].p[_i].t) {
              _i = i;
            }
          }
        }
      }
      if (_i != -1) {
        if ((p = _p) > 99) {
          printf("%s lost the game.\n", a[o].s.c_str());
          a[o].p[0] = e[++t], a[o].p[1] = e[++t], a[o].p[2] = e[++t];
          break;
        }
        printf("%s used %s%d,now p=%d.\n", a[o].s.c_str(), kS[a[o].p[_i].t].c_str(), a[o].p[_i].v, p);
        a[o].p[_i] = e[++t];
        continue;
      }
      bool _f = 0;
      for (int i = 5; i <= 7; ++i) {
        for (int j = 0; j < 3; ++j) {
          if (a[o].p[j].t == i) {
            a[o].p[j] = e[++t], i == 6 && (d = -d), f = i == 7, _f = 1;
            printf("%s used %s,now p=%d.\n", a[o].s.c_str(), kS[i].c_str(), p);
            break;
          }
        }
        if (_f) {
          break;
        }
      }
    }
  }
  return 0;
}

2021/9/25 18:57
加载中...