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+1≥Li+i) f i = max ( f j + ( F j + 1 + j + 1 ) × C i ) − i C i ( F