跳到正文

个人记录

史上最暴力代码

AC_Seed约 31 分钟
原文

这是 2025年10月8日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2025年10月3日
收录
2025年12月12日
更新
2026年10月27日
篇幅
约 31 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2005;
const int mod=998244353;
string s[maxn];
int n,k;
char a[maxn];
string sss;
int cnt[maxn];
bool vis[maxn];
int maxi=0;
int len=0;
map<string,int>mp;
void f2(int x){
	if(x>len){
		int cnt=0;
		char b[maxn];
		int t=0;
		for(int i=1;i<=len;i++){
			if(vis[i]){
				b[++t]=sss[i];
			}
		}
		for(int i=1;i<=t;i++) cout<<b[i];
		cout<<endl;
        cout<<len;
        cout<<endl;
		for(int i=1;i<t;i++){
			if(b[i]=='0'&&b[i+1]=='1'){
				continue;
			}
			else if(b[i]=='1'&&b[i+1]=='2'){
				continue;
			}
			else if(b[i]=='2'&&b[i+1]=='0'){
				continue;
			}
			else{
				return ;
			}
		}
		maxi=max(maxi,t);
		return ;
	}
	vis[x]=false;
	f2(x+1);
	
	vis[x]=true;
	f2(x+1);
	vis[x]=false;
}
void dfs(int x){
	if(x>n){
		sss="";
        for(int i=1;i<=n;i++) sss+=a[i];
        len=sss.size();
        sss=" "+sss;
        //cout<<sss<<endl;
        if(mp[sss]) return ;
        mp[sss]=true;
		memset(vis,0,sizeof(vis));
		//0:石头 1:剪刀 2:布
		maxi=0;
		f2(1);
		cnt[maxi]++;
		cnt[maxi]%=mod;
		return ;
	}
	string tmp=s[x];
	int len=tmp.size();
	tmp=" "+tmp;
	for(int i=1;i<=len;i++){
		a[x]=tmp[i];
		dfs(x+1);
		a[x]=' ';
	}
}
inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * f;
}

inline void write(int x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
inline __int128 read_128() {
    __int128 x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

void write_128(__int128 x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	n=read();
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	dfs(1);
	for(int i=1;i<=n;i++){
	    int val=cnt[i]%mod;
	    write(val);
	    printf(" ");
	}
	return 0;
}
/*
3
01 
12
02 
*/
/*
3
01 
12
02 
*/

T576073 【ptyb2025j】书法社

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e6+5;
inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return x * f;
}

inline void write(int x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
signed main(){
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//cout.tie(0);
    int n;
    cin>>n;
	string s;
	cin>>s;
	int cnt=0;
	int t=0;
	for(int i=0;i<n;i++){
		if(s[i]=='|'){
			bool flag1=false,flag2=false;
			int count=0;
			for(int j=i-1;j>=t;j--){
				if(s[j]=='2'&&count){
					flag1=true;
					break;
				}
				else if(s[j]=='2'){
					break;
				}
				else if(s[j]=='_'){
					count++;
					continue;
				}
				else{
					break;
				}
			}
			int count1=0;
			for(int j=i+1;j<n;j++){
				if(s[j]=='5'&&count1){
					flag2=true;
					break;
			    }
			    else if(s[j]=='5'){
			    	break;
				}
				else if(s[j]=='_'){
					count1++;
					continue;
				}
				else{
					break;
				}
			}
			if(flag2==false&&flag1==true&&count){
				cnt++;
				t=i;
			}
		}
	}
	
	int ans=0;
	for(int i=0;i<n;i++){
		if(s[i]=='2'){
			int len=0;
			int count=0;
			for(int j=i+1;j<n;j++){
				if(s[j]=='_'){
					count++;
					continue;
				}
				else if(s[j]=='|'&&count){
					ans++;
					len=j;
					break;
				}
				else{
					break;
				}
			}
		}
	}
	cout<<cnt<<" "<<ans<<" ";
	
	int cnt1=INT_MIN;
	int cnt2=INT_MAX;
	for(int i=0;i<n;i++){
		if(s[i]=='2'){
			int len=0;
			int count=0;
			for(int j=i+1;j<n;j++){
				if(s[j]=='_'){
					count++;
					continue;
				}
				else if(s[j]=='|'&&count){
					cnt1=max(cnt1,j-i+1);
					cnt2=min(cnt2,j-i+1);
					len=j;
					break;
				}
				else{
					break;
				}
			}
		}
	}
	if(cnt1==INT_MIN) cnt1=0;
	if(cnt2==INT_MAX) cnt2=0;
	cout<<cnt2<<" "<<cnt1<<"\n";
	
	
	
	cnt=0;
	ans=0;
	t=0;
	for(int i=0;i<n;i++){
		if(s[i]=='|'){
			bool flag1=false,flag2=false;
			int count=0;
			for(int j=i-1;j>=t;j--){
				if(s[j]=='2'&&count){
					flag1=true;
					break;
				}
				else if(s[j]=='2'){
					break;
				}
				else if(s[j]=='_'){
					count++;
					continue;
				}
				else{
					break;
				}
			}
			int count1=0;
			for(int j=i+1;j<n;j++){
				if(s[j]=='5'&&count1){
					flag2=true;
					break;
			    }
			    else if(s[j]=='5'){
			    	break;
				}
				else if(s[j]=='_'){
					count1++;
					continue;
				}
				else{
					break;
				}
			}
			if(flag1==false&&flag2==true&&count1){
				cnt++;
				t=i;
			}
		}
	}
	
	ans=0;
	for(int i=0;i<n;i++){
		if(s[i]=='|'){
			int len=0;
			int count=0;
			for(int j=i+1;j<n;j++){
				if(s[j]=='_'){
					count++;
					continue;
				}
				else if(s[j]=='5'&&count){
					ans++;
					len=j;
					break;
				}
				else{
					break;
				}
			}
		}
	}
	cout<<cnt<<" "<<ans<<" ";
	
	cnt1=INT_MIN;
	cnt2=INT_MAX;
	for(int i=0;i<n;i++){
		if(s[i]=='|'){
			int len=0;
			int count=0;
			for(int j=i+1;j<n;j++){
				if(s[j]=='_'){
					count++;
					continue;
				}
				else if(s[j]=='5'&&count){
					cnt1=max(cnt1,j-i+1);
					cnt2=min(cnt2,j-i+1);
					len=j;
					break;
				}
				else{
					break;
				}
			}
		}
	}
	if(cnt1==INT_MIN) cnt1=0;
	if(cnt2==INT_MAX) cnt2=0;
	cout<<cnt2<<" "<<cnt1<<"\n";
	return 0;
}

P2572 [SCOI2010] 序列操作

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1e6+5;
int n,m;
int a[maxn];
struct node{
    int l,r;
    int cnt0,cnt1;
    int lcnt0,lcnt1;
    int rcnt0,rcnt1;
    int op;
    int sum;
}tree[maxn<<2];
void push_up(int x){
    int lson = x<<1;
    int rson = x<<1|1;
    tree[x].sum = tree[lson].sum + tree[rson].sum;
    tree[x].lcnt0 = tree[lson].lcnt0;
    if(tree[lson].lcnt0 == tree[lson].r - tree[lson].l + 1){
        tree[x].lcnt0 += tree[rson].lcnt0;
    }
    tree[x].lcnt1 = tree[lson].lcnt1;
    if(tree[lson].lcnt1 == tree[lson].r - tree[lson].l + 1){
        tree[x].lcnt1 += tree[rson].lcnt1;
    }
    tree[x].rcnt0 = tree[rson].rcnt0;
    if(tree[rson].rcnt0 == tree[rson].r - tree[rson].l + 1){
        tree[x].rcnt0 += tree[lson].rcnt0;
    }
    tree[x].rcnt1 = tree[rson].rcnt1;
    if(tree[rson].rcnt1 == tree[rson].r - tree[rson].l + 1){
        tree[x].rcnt1 += tree[lson].rcnt1;
    }
    tree[x].cnt0 = max({tree[lson].cnt0, tree[rson].cnt0, tree[lson].rcnt0 + tree[rson].lcnt0});
    tree[x].cnt1 = max({tree[lson].cnt1, tree[rson].cnt1, tree[lson].rcnt1 + tree[rson].lcnt1});
    return ;
}
void build(int x,int l,int r){
    tree[x].l = l;
    tree[x].r = r;
    tree[x].op = -1;
    if(l == r){
        tree[x].sum = a[l];
        tree[x].cnt0 = (a[l] == 0);
        tree[x].cnt1 = (a[l] == 1);
        tree[x].lcnt0 = tree[x].rcnt0 = (a[l] == 0);
        tree[x].lcnt1 = tree[x].rcnt1 = (a[l] == 1);
        return ;
    }
    int mid = (l + r) >> 1;
    build(x<<1, l, mid);
    build(x<<1|1, mid+1, r);
    push_up(x);
}
void apply_op(int x, int op){
    if(op == 0){
        tree[x].sum = 0;
        tree[x].cnt0 = tree[x].r - tree[x].l + 1;
        tree[x].cnt1 = 0;
        tree[x].lcnt0 = tree[x].rcnt0 = tree[x].r - tree[x].l + 1;
        tree[x].lcnt1 = tree[x].rcnt1 = 0;
        tree[x].op = 0;
    } else if(op == 1){
        tree[x].sum = tree[x].r - tree[x].l + 1;
        tree[x].cnt1 = tree[x].r - tree[x].l + 1;
        tree[x].cnt0 = 0;
        tree[x].lcnt1 = tree[x].rcnt1 = tree[x].r - tree[x].l + 1;
        tree[x].lcnt0 = tree[x].rcnt0 = 0;
        tree[x].op = 1;
    } else if(op == 2){
        tree[x].sum = tree[x].r - tree[x].l + 1 - tree[x].sum;
        swap(tree[x].cnt0, tree[x].cnt1);
        swap(tree[x].lcnt0, tree[x].lcnt1);
        swap(tree[x].rcnt0, tree[x].rcnt1);
        if(tree[x].op == 0 || tree[x].op == 1){
            tree[x].op ^= 1;
        } else if(tree[x].op == 2){
            tree[x].op = -1;
        } else {
            tree[x].op = 2;
        }
    }
    return ;
}
void push_down(int x){
    if(tree[x].op == -1) {
    	return ;
	}
    apply_op(x<<1, tree[x].op);
    apply_op(x<<1|1, tree[x].op);
    tree[x].op = -1;
    return ;
}
void update(int x, int l, int r, int op){
    if(tree[x].r < l || tree[x].l > r) {
    	return ;
	}
    if(l <= tree[x].l && tree[x].r <= r){
        apply_op(x, op);
        return ;
    }
    push_down(x);
    update(x<<1, l, r, op);
    update(x<<1|1, l, r, op);
    push_up(x);
}
int query_sum(int x, int l, int r){
    if(tree[x].r < l || tree[x].l > r) {
    	return 0;
	}
    if(l <= tree[x].l && tree[x].r <= r) {
    	return tree[x].sum;
	}
    push_down(x);
    return query_sum(x<<1, l, r) + query_sum(x<<1|1, l, r);
}
int query_max1(int x, int l, int r){
    if(tree[x].r < l || tree[x].l > r) {
    	return 0;
	}
    if(l <= tree[x].l && tree[x].r <= r) {
    	return tree[x].cnt1;
	}
    push_down(x);
    int left_max = query_max1(x<<1, l, r);
    int right_max = query_max1(x<<1|1, l, r);
    int cross = min(tree[x<<1].r - l + 1, tree[x<<1].rcnt1) + min(r - tree[x<<1|1].l + 1, tree[x<<1|1].lcnt1);
    return max({left_max, right_max, cross});
}
signed main(){

    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    build(1,1,n);
    while(m--){
        int op,l,r;
        cin>>op>>l>>r;
        l++; 
		r++; 
        if(l > r) swap(l, r);
        if(op == 0){
            update(1, l, r, 0);
        } 
		else if(op == 1){
            update(1, l, r, 1);
        } 
		else if(op == 2){
            update(1, l, r, 2);
        } 
		else if(op == 3){
            cout<<query_sum(1, l, r)<<"\n";
        } 
		else if(op == 4){
            cout<<query_max1(1, l, r)<<"\n";
        }
    }
    return 0;
}

P2482 [SDOI2010] 猪国杀

C++
#include<bits/stdc++.h>
using namespace std;
struct node {
	int cs, hp, next, last;
	char id, card[2010];
	bool zgln;
} a[20];

char kn[11], kpd[2010], sss[10];
int n, m, fz;
bool ed;

void mp(int x) {
	if (!m) m++;

	a[x].card[++a[x].cs] = kpd[m];
	m--;
}

void js(int x1, int x2) {
	for (int i = 1; i <= a[x2].cs; i++) {
		if (a[x2].card[i] == 'P') {
			a[x2].card[i] = 'U';
			a[x2].hp++;
			return ;
		}
	}

	a[a[x2].next].last = a[x2].last;
	a[a[x2].last].next = a[x2].next;

	if (x2 == 1) {
		ed = true;
		return ;
	}

	if (a[x2].id == 'F') {
		fz--;
	}

	if (!fz) {
		ed = true;
		return ;
	}

	if (a[x2].id == 'F') {
		mp(x1);
		mp(x1);
		mp(x1);
	}

	if (a[x2].id == 'Z' && a[x1].id == 'M') {
		a[x1].cs = 0, a[x1].zgln = false;
	}
}

void Kil(int x1, int x2) {
	for (int i = 1; i <= a[x2].cs; i++) {
		if (a[x2].card[i] == 'D') {
			a[x2].card[i] = 'U';
			return ;
		}
	}

	a[x2].hp--;

	if (!a[x2].hp) js(x1, x2);
}

bool wxkj(int x1, int x2, int x3) {
	int i = x1;
	int pd = x3 ? x2 : x1;

	while (1) {
		if (x3 == 1) {
			if (kn[x2] == a[i].id || (kn[x2] == 'M' && a[i].id == 'Z') || (kn[x2] == 'Z' && a[i].id == 'M'))

				for (int j = 1; j <= a[i].cs; j++)
					if (a[i].card[j] == 'J') {
						a[i].card[j] = 'U';
						kn[i] = a[i].id;
						return !wxkj(i, x1, 0);
					}
		} else {
			if (((a[i].id == 'M' || a[i].id == 'Z') && kn[x1] == 'F') || (a[i].id == 'F' && (kn[x1] == 'M' || kn[x1] == 'Z')))
				for (int j = 1; j <= a[i].cs; j++)
					if (a[i].card[j] == 'J') {
						a[i].card[j] = 'U';
						kn[i] = a[i].id;
						return !wxkj(i, x1, 0);
					}
		}

		i = a[i].next;

		if (i == x1) break;
	}

	return false;
}

void nmrq(int x1) {
	for (int x2 = a[x1].next; x2 != x1; x2 = a[x2].next)

		if (!wxkj(x1, x2, 1)) {
			int i;

			for (i = 1; i <= a[x2].cs; i++)
				if (a[x2].card[i] == 'K') {
					a[x2].card[i] = 'U';
					break;
				}

			if (i > a[x2].cs) {
				a[x2].hp--;

				if (x2 == 1 && kn[x1] == 'U') kn[x1] = 'L';

				if (!a[x2].hp) js(x1, x2);

				if (ed) return ;
			}
		}
}

void wjqf(int x1) {
	for (int x2 = a[x1].next; x2 != x1; x2 = a[x2].next)
		if (!wxkj(x1, x2, 1)) {
			int i;

			for (i = 1; i <= a[x2].cs; i++)
				if (a[x2].card[i] == 'D') {
					a[x2].card[i] = 'U';
					break;
				}

			if (i > a[x2].cs) {
				a[x2].hp--;

				if (x2 == 1 && kn[x1] == 'U') kn[x1] = 'L';

				if (!a[x2].hp) js(x1, x2);

				if (ed) return ;
			}
		}
}

void jd(int x1, int x2) {
	int i, j, k;

	if (wxkj(x1, x2, 1)) return ;

	if (x1 == 1 && a[x2].id == 'Z') {
		a[x2].hp--;

		if (!a[x2].hp) js(x1, x2);

		return ;
	}

	j = k = 1;

	while (1) {
		while (a[x2].card[j] != 'K' && j <= a[x2].cs) j++;

		if (j > a[x2].cs) {
			a[x2].hp--;

			if (!a[x2].hp) js(x1, x2);

			return ;
		} else a[x2].card[j] = 'U';

		while (a[x1].card[k] != 'K' && k <= a[x1].cs) k++;

		if (k > a[x1].cs) {
			a[x1].hp--;

			if (!a[x1].hp) js(x2, x1);

			return ;
		} else a[x1].card[k] = 'U';
	}
}

void hh() {
	char nc;
	ed = true;

	if (fz) ed = false;

	if (ed) return ;

	for (int i = 1; i; i = a[i].next) {
		mp(i), mp(i);
		bool kill = true;

		for (int j = 1; j <= a[i].cs; j++)
			if (a[i].card[j] != 'U') {
				if (!a[i].hp) break;

				nc = a[i].card[j];

				if (nc == 'P') {
					if (a[i].hp != 4) a[i].hp++, a[i].card[j] = 'U';

					continue;
				}

				if (nc == 'K') {
					if (!kill && !a[i].zgln) continue;

					if (a[i].id == 'M' && kn[a[i].next] != 'L' && kn[a[i].next] != 'F') continue;

					if (a[i].id == 'Z' && kn[a[i].next] != 'F') continue;

					if (a[i].id == 'F' && kn[a[i].next] != 'Z' && kn[a[i].next] != 'M') continue;

					a[i].card[j] = 'U';
					Kil(i, a[i].next);
					kn[i] = a[i].id, kill = false;

					if (ed) return ;

					continue;
				}

				if (nc == 'F') {
					if (a[i].id == 'F') {
						a[i].card[j] = 'U', jd(i, 1);
						kn[i] = a[i].id;

						if (ed) return ;

						j = 0;
						continue;
					}

					for (int k = a[i].next; k != i; k = a[k].next)
						if ((a[i].id == 'M' && (kn[k] == 'L' || kn[k] == 'F')) || (a[i].id == 'Z' && kn[k] == 'F')) {
							a[i].card[j] = 'U', jd(i, k);
							kn[i] = a[i].id;

							if (ed) return ;

							j = 0;
							break;
						}

					continue;
				}

				if (nc == 'N') {
					a[i].card[j] = 'U';
					nmrq(i);

					if (ed) return ;

					j = 0;
					continue;
				}

				if (nc == 'W') {
					a[i].card[j] = 'U';
					wjqf(i);

					if (ed) return ;

					j = 0;
					continue;
				}

				if (nc == 'Z') {
					a[i].zgln = true;
					a[i].card[j] = 'U';
					j = 0;
					continue;
				}
			}
	}
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		a[i].next = i + 1;
		a[i].last = i - 1;
	}
	a[n].next = 1;
	a[1].last = n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < 2010; j++) a[i].card[j] = 'U';
		cin >> sss;
		a[i].id = sss[0];
		for (int j = 1; j <= 4; j++) {
			cin >> sss;
			a[i].card[j] = sss[0];
		}
		a[i].cs = a[i].hp = 4;
		if (a[i].id == 'F') fz++;
		a[i].zgln = false;
	}
	for (int i = 2; i <= n; i++) {
		kn[i] = 'U';
    }
	kn[1] = 'M';
	for (int i = 1; i <= m; i++) {
		cin >> sss;
		kpd[m - i + 1] = sss[0];
	}
	hh();
	if (a[1].hp <= 0) {
		cout << "FP" << endl;
	} else {
		cout << "MP" << endl;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i].hp <= 0) {
			cout << "DEAD" << endl;
		} else {
			for (int j = 1; j <= a[i].cs; j++) {
				if (a[i].card[j] != 'U') {
					cout << a[i].card[j] << " ";
				}
			}
			cout << endl;
		}
	}
	return 0;
}