NOIP2023

T1 太简单直接 sort 排序和 reverse 反过来就可以了。

点击查看代码
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define For(i,l,r) for(int i=l;i<=r;i++) 
int n,m;
const int N=3e3+10;
char w[N][N];
char mn[N][N];
char mx[N][N];
char a[N];
int cnt;
bool chk(char s[],char s2[]){
	For(i,1,m){
		if(s[i]<s2[i])return 1;
		if(s[i]>s2[i])return 0;
	}
	return 1;
}
int main(){
//	freopen("dict4.in","r",stdin);
//	freopen("dict4.out","w",stdout);
	ios::sync_with_stdio(0); 
	cin.tie(0);cout.tie(0); 
	cin>>n>>m;
	For(i,1,n)cin>>(w[i]+1);
	For(i,1,n){
		cnt=0;
		For(j,1,m){
			a[++cnt]=w[i][j];
		}
		sort(a+1,a+cnt+1);
		For(j,1,cnt)mn[i][j]=a[j];
		reverse(a+1,a+cnt+1);
		For(j,1,cnt)mx[i][j]=a[j];
	}
	For(i,1,n){
		bool f=0;
		For(j,1,n){
			if(j==i)continue;
			if(chk(mx[j],mn[i])){
				f=1;cout<<0;break;
			}
		}
		if(!f)cout<<1;
	}
	return 0; 
}

T2 思路很水但是不算很好写。

分类讨论。找最后一次赋值的地方。

  • 一个点前面操作没出现赋值

    • 奇数次取反 $\rightarrow \ U $
    • 否则不是 \(U\)
  • 前面出现 \(v\) 类赋值。

    • 取反后与原来不等 $\rightarrow \ U $
    • 否则不是 \(U\)
  • 前面出现 \(x_j\) 类赋值。

    • 建图,\(x_j \rightarrow x_i\)。因为最后一次赋值只有一个数,所以每个点只有一个父亲。
      最终可能连成一棵树,当然也有可能形成环。边权定为赋值后非运算次数的奇偶性。
      按照异或来算路上权值。

考虑第三种情况什么时候会出现 \(U\)

手玩后发现出现奇数个 \(1\) 参与异或时,会使得环上的每个点走完一圈推出了与自己相反的结论。这时环上点全是 \(U\) 才行。以及 \(U\) 推出的儿子都是 \(U\)(根据运算性质易得)。

另外还有绝妙做法并查集。

点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
const int T=100001;
const int F=-100001;
const int U=0;
#define For(i,l,r) for(int i=l;i<=r;i++)
int n,m,fa[N];
bool f[3*N];
int find(int x){
    int res;
	if(x==T||x==F)res=x;
	else if(f[n-x]||x==U)res=U;
	else if(f[x+n])res=T;
	else if(x<0){
		if(x==-fa[-x])res=x;
		else{
			f[x+n]=1;
            res=find(-fa[-x]);
			f[x+n]=0;
		}
	}
    else{
		if(x==fa[x])res=x;
		else{
			f[x+n]=1;
			res=fa[x]=find(fa[x]);
			f[x+n]=0;
		}
	}
    return res;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	int c,t;cin>>c>>t;
	while(t--){
		cin>>n>>m;
		For(i,1,n)fa[i]=i;
		For(i,1,m){
			char op;cin>>op;int a,b;
			if(op=='T'){cin>>a;fa[a]=T;}
            else if(op=='F'){cin>>a;fa[a]=F;}
            else if(op=='U'){cin>>a;fa[a]=U;}
            else{
				cin>>a>>b;
				if(op=='+')fa[a]=fa[b];
				else fa[a]=-fa[b];
			}
		}
		int ans=0;
		For(i,1,n){if(find(i)==U)ans++;}
		cout<<ans<<"\n";
	}
	return 0;
}

T3 太吃注意力了,主播只会 \(O(Tnm)\)

posted @ 2025-10-11 20:52  Accept_Reality  阅读(3)  评论(0)    收藏  举报