跳到正文

个人记录

6.19总结

JWM918约 10 分钟
原文
文章信息与版本

文章信息

发布
2026年6月25日
收录
2026年6月25日
更新
2026年11月14日
篇幅
约 10 分钟

版本

  1. v3当前
  2. v2
  3. v1

6.19总结

课堂总结

P16713{\color{Orange}{P16713}} 相思

题目传送门(比赛)

考察知识点

  • 数论

错误原因

  • WA{\color{Red}{WA}}:逻辑判断完全错误

错误思路

用双重循环判断所有可能中是否有可能和为质数,有可能则Edisnrub胜,否则Burnside胜

错误代码(WA){\color{Red}{(WA)}}:

错误代码
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int l1,r1,l2,r2;
bool st[200005]={1,1};
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
  //质数判断(预处理)
	for(int i=2;i<=200000;i++){
		if(st[i])continue;
		for(int j=i+i;j<=200000;j+=i){
			st[j]=1;
		}
	}
	cin>>l1>>r1>>l2>>r2;
	for(int i=l1;i<=r1;i++){
		for(int j=l2;j<=r2;j++){
			if(st[i+j])continue;
			cout<<"Edisnrub\n";
			return 0;
		}
	}
	cout<<"Burnside\n";
	return 0;
}

正确思路

用双重循环判断所有可能中是否存在Burnside选的数让Edisnrub无论如何都无法让和为质数的情况,有可能则Burnside胜,否则Edisnrub胜。因为连续非质数个数≤100≤100,所以暴力枚举不会超时

正确代码(AC){\color{Green}{(AC)}}:

正确代码
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int l1,r1,l2,r2;
bool isPrime(int x){
	for(int i=2;i*i<=x;i++){
		if(x%i==0)return 0;
	}
	return 1;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>l1>>r1>>l2>>r2;
	for(int i=l1;i<=r1;i++){
		bool f=0;//存在Burnside选的数让Edisnrub无论如何都无法让和为质数的情况为0,否则为1
		for(int j=l2;j<=r2;j++){
			if(isPrime(i+j)){
				f=1;
				break;
			}
		}
		if(!f){
			cout<<"Burnside\n";
			exit(0);
		}
	}
	cout<<"Edisnrub\n";
	return 0;
}

T772411{\color{Gray}{T772411}} 旋转之乘

题目传送门(比赛)

考察知识点

  • 广度优先搜索(BFSBFS)

错误原因

  • WA{\color{Red}{WA}}:把末尾的数字移动到字符串的开头时未考虑t<10t<10且tt能被1010整除的情况

错误思路

用BFSBFS搜索到达终点的最短路径

错误代码(32分){\color{Orange}{(32分)}}:

错误代码
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a,n;
bool st[1000005];
struct node{
	int x,step;
};
queue<node>q;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>n;
  //增加起点的影响
	st[1]=1;
	q.push({1,0});
  //搜索
	while(q.size()){
		node t=q.front();
		q.pop();
    //到达终点
		if(t.x==n){
			cout<<t.step<<endl;
			return 0;
		}
    //操作1
		int nx=t.x*a;
		if(nx<=1000000&&!st[nx]){
			st[nx]=1;
			q.push({nx,t.step+1});
		}
    //操作2
		nx=t.x<10?t.x:n/10+n%10*(int)pow(10,(int)log10(n/10)+1);
		if(!st[nx]){
			st[nx]=1;
			q.push({nx,t.step+1});
		}
	}
  //无法到达
	cout<<-1<<endl;
	return 0;
}

正确思路

用BFSBFS搜索到达终点的最短路径即可。注意把末尾的数字移动到字符串的开头时只有当t≥10t≥10且tt不能被1010整除时才能进行操作

正确代码(100分){\color{Green}{(100分)}}:

正确代码
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a,n,dis[1000005];
bool st[1000005];
queue<int>q;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>n;
  //增加起点的影响
	st[1]=1;
	dis[1]=0;
	q.push(1);
  //搜索
	while(q.size()){
		int t=q.front();
		q.pop();
    //操作1
		int nx=t*a;
        if(nx<=1000000&&!st[nx]){
			st[nx]=1;
			dis[nx]=dis[t]+1;
			q.push(nx);
		}
    //操作2
		int x=t,len=0;
		while(x)len++,x/=10;//计算log10(n/10)
		nx=t%10*pow(10,len-1)+t/10;
		if(nx>10&&t%10&&!st[nx]){
			st[nx]=1;
			dis[nx]=dis[t]+1;
			q.push(nx);
		}
	}
	if(st[n])cout<<dis[n]<<endl;//有解
	else cout<<-1<<endl;//无解
	return 0;
}

T772460{\color{Gray}{T772460}} 集合覆盖

题目传送门(比赛)

考察知识点

  • 深度优先搜索(DFSDFS)

错误原因

  • WA{\color{Red}{WA}}:DFS的结束条件错误

错误思路

(与正确思路一致,见下文“正确思路”)

错误代码(91分){\color{YellowGreen}{(91分)}}:

错误代码
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,m,s[15][15],ans;
map<int,int>ma;
void dfs(int x){
	if(x>n){
		if(ma.size()==n)ans++;
		return;
	}
  //选该集合
	for(int i=1;i<=s[x][0];i++){
		ma[s[x][i]]++;
	}
	dfs(x+1);
  //不选该集合
	for(int i=1;i<=s[x][0];i++){
		ma[s[x][i]]--;
		if(ma[s[x][i]]==0)ma.erase(s[x][i]);
	}
	dfs(x+1);
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>s[i][0];
		for(int j=1;j<=s[i][0];j++){
			cin>>s[i][j];
			ma[s[i][j]]++;
		}
	}
	if(ma.size()<n){
		cout<<0<<endl;
		return 0;
	}
	ma.clear();
	dfs(1);
	cout<<ans<<endl;
	return 0;
}

正确思路

用DFSDFS搜索出所有可能,再统计答案即可

正确代码(100分){\color{Green}{(100分)}}:

正确代码
C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int n,m,s[15][15],ans;
map<int,int>ma;
void dfs(int x){
	if(x>m){
		if(ma.size()==n)ans++;
		return;
	}
  //选该集合
	for(int i=1;i<=s[x][0];i++){
		ma[s[x][i]]++;
	}
	dfs(x+1);
  //不选该集合
	for(int i=1;i<=s[x][0];i++){
		ma[s[x][i]]--;
		if(ma[s[x][i]]==0)ma.erase(s[x][i]);
	}
	dfs(x+1);
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>s[i][0];
		for(int j=1;j<=s[i][0];j++){
			cin>>s[i][j];
			ma[s[i][j]]++;
		}
	}
	if(ma.size()<n){
		cout<<0<<endl;
		return 0;
	}
	ma.clear();
	dfs(1);
	cout<<ans<<endl;
	return 0;
}
原文