标签:构造
题目大意:
分析:
AC code:
#include <bits/stdc++.h>
#define inv(n, x) ((n)-(x)+1)
#define pii pair<int,int>
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof a)
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
typedef long long LL;
typedef double DB;
typedef long double LD;
using namespace std;
void open_init()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
}
void close_file()
{
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
}
const int MAXN = 4100;
int n;
char str[MAXN];
bitset<MAXN> cur, nxt;
char src;
int s[2], l;
inline void add(char c)
{
s[c==src]++, cur[++l] = c==src;
}
int main()
{
open_init();
scanf("%d\n%c", &n, &src);
s[1]++, cur[++l] = 1;
puts("Qc");puts("0 0");
for(int i = 2, mid = 2; i <= n; ++i, ++mid)
{
add(getchar()), add(getchar());
bitset<MAXN> tmp;
rep(k, 0, 1)
{
int ts[2] = {s[0], s[1]};
if(ts[0]&1) tmp[mid] = 0, ts[0]--;
else tmp[mid] = 1, ts[1]--;
for(int j = 1, tk = k; j < mid; ++j, tk ^= 1)
if(!ts[tk]) tmp[j] = tmp[l-j+1] = tk^1, ts[tk^1] -= 2;
else tmp[j] = tmp[l-j+1] = tk, ts[tk] -= 2;
if(!k || (tmp^cur).count() < (nxt^cur).count()) nxt = tmp;
}
vector<int> p[2];
rep(j, 1, l)
if(nxt[j] != cur[j])
p[cur[j]].pb(j);
rep(j, p[0].size()+1, 2)
puts("0 0");
rep(j, 0, (int)p[0].size()-1)
printf("%d %d\n", p[0][j], p[1][j]);
cur = nxt;
}
close_file();
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:构造
原文地址:http://blog.csdn.net/qq_20118433/article/details/47074289