跳到正文

个人记录

9.18-甜菜测试-410

yangziqiao约 8 分钟
原文
文章信息与版本

文章信息

发布
2026年9月26日
收录
2026年9月26日
更新
2026年11月11日
篇幅
约 8 分钟

版本

  1. v1当前

题目列表

A 100 [GESP202609 五级] 哥德巴赫猜想

B 100 掐头去尾 / Delete and Backspace

C 100 月色的快乐路径

D 100 [GESP202609 七级] 必经之路

E 99.89999999999999 [GKS 2019 #C] Wiggle Walk 未提交

A题

❌️错误思路:{\color{red}错误思路:}

  • 用常规的找质数方法来做

❌️错误结果:{\color{red}错误结果:}

  • 被TLE制裁了
❌️错误代码:{\color{red}错误代码:}
C++
#include<bits/stdc++.h>
using namespace std;
int fff(int xxx)
{
	for(int i=2;i<=xxx/i;i++)
	{
		if(xxx%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	int n;
	cin>>n;
	int ans=0;
	int cnt=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=2;j<=n;j++)
		{
			if(fff(i)&&fff(j)&&i+j==n)
			{
				ans++;
				if(i!=j)cnt++;
				
			}
		}
	}
	cout<<ans-cnt/2;
    return 0;
}

✅️正确思路:{\color{green}正确思路:}

  • 使用埃氏筛,寻找质数

✅️

正确代码:{\color{green} 正确代码}\color{green}:
C++
#include<bits/stdc++.h>
using namespace std;
int fff(int xxx)
{
    if(xxx<=1)return 0;
	for(int i=2;i<=xxx/i;i++)
	{
		if(xxx%i==0)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	int n;
	cin>>n;
	int ans=0;
	
	for(int i=2;i<=n/2;i++)
	{
		if(fff(i)&&fff(n-i))
		{
				ans++;
				
				
		}
		
	}
	cout<<ans;
    return 0;
}

B题

❌️错误思路:{\color{red}错误思路:}

  • 无

❌️错误结果:{\color{red}错误结果:}

  • 无
❌️错误代码:{\color{red}错误代码:}
C++
//无

✅️正确思路:{\color{green}正确思路:}

  • 暴力

✅️

正确代码:{\color{green} 正确代码}\color{green}:
C++
#include<bits/stdc++.h>
using namespace std;
int a[100010];
int main()
{
	int n;
	cin>>n;
	
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		ans=max(ans,max(a[i],a[n-i+1]));
		cout<<ans<<' ';
	}
    return 0;
}


C题

❌️错误思路:{\color{red}错误思路:}

  • 无

❌️错误结果:{\color{red}错误结果:}

  • 无
❌️错误代码:{\color{red}错误代码:}
C++
//无

✅️正确思路:{\color{green}正确思路:}

  • 从起点到终点的每一种路线都用 dfs 去走一遍求出所有满足条件的路线,然后记录所有走过的数值

✅️

正确代码:{\color{green} 正确代码}\color{green}:
C++
#include<bits/stdc++.h>
using namespace std;
int n,m,a[15][15],ans,d[2][2]={{0,1},{1,0}},vis[15][15];
map<int,int>mp;
void dfs(int x,int y)
{
    if(x==n&&y==m)
    {
        ans++;
        return ;
    }
    for(int i=0;i<2;i++)
    {
        int dx=x+d[i][0],dy=y+d[i][1];
        if(dx<=n&&dy<=m&&mp[a[dx][dy]]==0)
        {
            mp[a[dx][dy]]++;
            dfs(dx,dy);
            mp[a[dx][dy]]--;
        }
    }
}
int main()
{
	cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    vis[1][1]=1;
    mp[a[1][1]]++;
    dfs(1,1);
    cout<<ans;
    return 0;
}

D题

❌️错误思路:{\color{red}错误思路:}

  • 无

❌️错误结果:{\color{red}错误结果:}

  • 无
❌️错误代码:{\color{red}错误代码:}
C++
//无

✅️正确思路:{\color{green}正确思路:}

  • 必经点去掉之后所有合法起点到所有合法终点就没法走了,所以我们可以把每一个点都去掉一次,如果去掉了就不能走了,那么那个点就是必经点,但是起点和终点不止一个,所有我们可以建立一个点,让这个点连接所有合法起点,再建立一个点,让所有合法终点连接这个点

✅️

正确代码:{\color{green} 正确代码}\color{green}:
C++
#include<bits/stdc++.h>
using namespace std;
vector<int>a[1011];
int cnt[10010],cnt1[10010];
int vis[1010];
void dfs(int x)
{
    
    vis[x]=1;
        
    
    
    for(auto i:a[x])
    {
        
        if(!vis[i])
        {
            vis[i]=1;
            dfs(i);
            
        }
    }
    
    return;
}
int main(){
    
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        a[x].push_back(y);
        cnt[y]++;
        cnt1[x]++;
        
    }
    for(int i=1;i<=n;i++)    
    {
        if(cnt[i]==0)
        {
            a[0].push_back(i);
        }
        if(cnt1[i]==0)
        {
            a[i].push_back(n+1);
        }
    }
    vector<int>ans;
    for(int i=1;i<=n;i++)
    {
        memset(vis,0,sizeof vis);
        vis[i]=1;dfs(0);
        for(int j=1;j<=n;j++)
        {
            vis[j]=0;
        }
        if(vis[n+1]==0)
        {
            ans.push_back(i);
        }
        
        
    }
    cout<<ans.size()<<'\n';
    for(int j=0;j<ans.size();j++)
    {
        cout<<ans[j]<<' ';
    }
    
    return 0;
}

原文