跳到正文

个人记录

6月2日 401刷题总结

_starry_night约 6 分钟
原文
文章信息与版本

文章信息

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

版本

  1. v1当前

6月2日 401刷题总结

AS01 辣椒炒肉

代码如下

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=911;
int t;
int x,y;
bool vis[N][N];
int dx[]={2,0};
int dy[]={0,2};
void dfs(int sx,int sy,int fs,int fy,int mf){
	if(mf==1){
		if(sx+1<=10)dfs(sx+1,sy,sx,sy,0);
		if(sy+1<=10)dfs(sx,sy+1,sx,sy,0);
	}
	for(int i=0;i<2;i++){
		int xx=sx+dx[i];
		int yy=sy+dy[i];
		if(xx>=0&&yy>=0&&xx<=10&&yy<=10&&vis[xx][yy]!=1&&(xx!=sx||yy!=sy)){
			vis[xx][yy]=1;
			dfs(xx,yy,fs,fy,mf);
		}
	}
}
signed main()
{
	//  freopen("as01.in","r",stdin);
	//  freopen("as01.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	dfs(0,0,0,0,1);
	while(t--)
	{
		cin>>x>>y;
		if(!vis[x][y])
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
	}
	return 0;
}
/*
6
 1 1
 1 2
 4 6
 5 9
 7 2
 10 10
*/

AS02 构造原数组

错误原因:条件判断式漏判末尾

思路:

1.非-1 -> 直接存入bib_i(去除-1)

2.开头-1 (也就是a1==−1a_1==-1)-> 将a1a_1变成ana_n,若an==0a_n==0则将a1,ana_1,a_n都变成0

3.结尾-1->因为上面排除了首尾-1的情况,因此只需让bn==a1b_n==a_1即可

4.最后输出abs(bn−b1)abs(b_n-b_1)和b1至bnb_1至b_n即可

代码如下:

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+25;
int t;
int n,a[N],b[N];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=-1)
			{
				b[i]=a[i];
			}
			else if(i==1)
			{
				if(a[n]==-1)
				{
					a[1]=0;
					a[n]=0;
				}
				b[1]=a[n];
			}
			else if(i==n)
			{
				b[i]=a[1];
			}
			else
			{
				b[i]=0; 
			}
		}
		cout<<abs(b[1]-b[n])<<endl;
		for(int i=1;i<=n;i++)
		{
			cout<<b[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

AS03 红心6

代码如下

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+25;
int t;
int n,o;
int a[N],b[N];
signed main()
{
//	freopen("as03.in","r",stdin);
//	freopen("as03.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n;
		o=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]%6==0)
			{
				b[++o]=a[i];
				a[i]=-1;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(a[i]==-1)
			{
				continue;
			}
			if(a[i]%3==0)
			{
				b[++o]=a[i];
				a[i]=-1;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(a[i]==-1)
			{
				continue;
			}
			if(a[i]%2!=0)
			{
				b[++o]=a[i];
				a[i]=-1;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(a[i]==-1)
			{
				continue;
			}
			if(a[i]%2==0)
			{
				b[++o]=a[i];
				a[i]=-1;
			}
		}
		for(int i=1;i<=n;i++)
		{
			cout<<b[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}
/*
5
6
12 7 9 4 18 5
4
3 6 2 8
7
1 10 15 20 3 6 9
5
11 14 21 2 5
3
6 6 6
*/

原文