CodeForces Gym 101806 简要题解

Puyo Puyo

首先把有奇数个东西的列用 [1,2],[2,2],[2,2] [ 1 , 2 ] , [ 2 , 2 ] , [ 2 , 2 ] 消成偶数个东西,然后依次放就行了。

#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 25;

vector <pair <pii, pii>> ans;
vector <int> a[N];
int n, m, k;

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), Read(m), Read(k);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1, x; j <= m; ++j) {
      Read(x);
      if (x) {
        a[j].pb(x);
      }
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (a[i].size() & 1) {
      int c = a[i].back(), d = c == 1 ? 2 : 1;
      ans.pb(mp(mp(1, i), mp(d, c)));
      ans.pb(mp(mp(1, i), mp(d, d)));
      ans.pb(mp(mp(1, i), mp(d, d)));
      a[i].pop_back();
    }
    reverse(a[i].begin(), a[i].end());
  }
  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j < a[i].size(); j += 2) {
      ans.pb(mp(mp(1, i), mp(a[i][j + 1], a[i][j])));
    }
  }
  printf("%d\n", ans.size());
  for (auto p : ans) {
    printf("%d %d %d %d\n", p.X.X, p.X.Y, p.Y.X, p.Y.Y);
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}

QueryreuQ

对于每个串跑Manacher即可。

#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 20005;

int n, m, a[N], f[N];
char s[N], t[N];

inline int Manacher() {
  for (int i = 1; i <= m; ++i) {
    a[i << 1] = t[i], a[i << 1 | 1] = -1;
  }
  a[0] = -2, a[1] = -1, a[m + 1 << 1] = -3;
  int ans = 0;
  for (int i = 2, r = 0, p = 0; i < m + 1 << 1; ++i) {
    f[i] = r > i ? min(r - i, f[(p << 1) - i]) : 1;
    for (; a[i - f[i]] == a[i + f[i]]; ++f[i]);
    if (CheckMax(r, i + f[i])) {
      p = i;
    }
    ans += f[i] >> 1;
  }
  return ans;
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == '-') {
      --m;
    } else {
      t[++m] = s[i];
    }
    printf("%d%c", Manacher(), i == n ? '\n' : ' ');
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}

Recipe

考虑暴力DP, fi=max(fj+(Fj+1+j+1)×Ci)iCi(Fj+1+j+1Li+i) f i = max ( f j + ( F j + 1 + j + 1 ) × C i ) − i C i ( F

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值