跳到正文

个人记录

24春季练习赛0521标程

tlzx_px约 14 分钟
原文
文章信息与版本

文章信息

发布
2024年6月4日
收录
2026年9月3日
更新
2026年11月17日
篇幅
约 14 分钟

版本

  1. v1当前

[AtCoder-abc309_a] [Problem A] 代码源自 cccyyymmm||草履虫万岁​ 程彦铭 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
	cin>>a>>b;
	if(a+1==b&&a!=3&&a!=6) {
		cout<<"Yes";
	}
	else{
		cout<<"No"; 
	}
    return 0;
}

B [AtCoder-abc318_a] [Problem B] 代码源自 DTY0513 (0513dty)(董腾远) 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
int n,m,p,ans=0;
int main(){
	cin>>n>>m>>p;
	for(int i=m;i<=n;i+=p){
		ans++;
	}
	cout<<ans;
	return 0;
} 

[AtCoder-abc309_b] [Problem C] 代码源自 ganyuchen123​ 甘宇晨 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
char a[200][200],b[200][200];
int c;
int main(){
	cin>>c;
	for(int i=1;i<=c;i++){
		for(int j=1;j<=c;j++) cin>>a[i][j];
	}
	for(int i=1;i<=c;i++){
		for(int j=1;j<=c;j++){
			if(i!=1&&i!=c&&j!=1&&j!=c) b[i][j]=a[i][j];
			if(i==1&&j<c) b[i][j+1]=a[i][j];
			if(i==c&&j>1) b[i][j-1]=a[i][j];
			if(i>1&&j==1) b[i-1][j]=a[i][j];
			if(i<c&&j==c) b[i+1][j]=a[i][j];
		}
	}
	for(int i=1;i<=c;i++){
		for(int j=1;j<=c;j++) cout<<b[i][j];
		cout<<"\n";
	}
}

D [AtCoder-abc317_b] [Problem D] 代码源自 fangchengyu​龚梓浩 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
int n,a[110];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		if(a[i+1]!=a[i]+1){
			cout<<a[i]+1;
			return 0;
		}
	}
	return 0;
}

[AtCoder-abc318_b] [Problem E] 代码源自 Hzz20240514​ 黄泽正 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
int n,a[100],b[100],c[100],d[100],x[100][100];
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i]>>d[i];
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++) x[i][j]=0;
	}for(int i=0;i<n;i++){
		for(int j=a[i];j<b[i];j++){
			for(int k=c[i];k<d[i];k++){
				x[j][k]=1;
			}
		}
	}int ans=0;
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			if(x[i][j]==1) ans++;
		}
	}cout<<ans;
    return 0;
}

[AtCoder-abc318_c] [Problem F] 代码源自DTY0513​ 董腾远 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
long long n,d,p;
long long a[200001];
long long sum[200001],ans;
int cmp(long long a,long long b){
	return a>b;
}
int main(){
	scanf("%d%d%d",&n,&d,&p);
	for(long long i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n,cmp);
	for(long long i=1;i<=n;i++){
		sum[i]=sum[i-1]+a[i];
	}
//	for(int i=1;i<=n;i++){
//		cout<<a[i]<<" ";
//	}
//	cout<<"\n";
//	for(int i=1;i<=n;i++){
//		cout<<sum[i]<<" ";
//	}
//	cout<<"\n";
	ans=sum[n];
	for(long long i=d;i<=n;i+=d){
		long long res=sum[i];
		res=res-i/d*p;
		if(sum[n]-res<ans){
			ans=sum[n]-res;
		}
//		cout<<ans<<" ";
	}
	long long id=(n+d-1)/d;
//	cout<<id*p;
	if(id*p<ans) ans=id*p;
	printf("%lld",ans);
	return 0;
} 

[AtCoder-abc317_c] [Problem G] 代码源自 CEFqwq​ 许嘉懿 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define R(a) cin >> a
#define P(a) cout << a
int n, m;
int f[100][100], ans[20], nans[20];
double T, T0 = 1e5, Tk = 1e-6, d = 0.985;
int Ans = 0;
int calc(){
	int res = 0, xz = 0;
	fr (i, 1, n - 1)
		if (f[nans[i]][nans[i + 1]] == -1)
			res = max(res, xz), xz = 0;
		else
			xz += f[nans[i]][nans[i + 1]];
	res = max(res, xz);
	return res;
}
void th(){
	T = T0;
	while (T > Tk){
		int ns = calc();
		int sx = rand() % n + 1, sy = rand() % n + 1;
		swap(nans[sx], nans[sy]);
		int nws = calc();
		if (nws > ns)
			swap(ans[sx], ans[sy]);
		else{
			double gl = rand() * 1.0 / RAND_MAX;
			if (gl < exp(abs(nws - ns) / T))
				swap(ans[sx], ans[sy]);
			else
				swap(nans[sx], nans[sy]);
		}
		T *= d;
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	srand(time(0));
	srand(rand());
	R(n) >> m;
	fr (i, 1, n)
		fr (j, 1, n)
			f[i][j] = -1;
	fr (i, 1, m){
		int u, v, c;
		R(u) >> v >> c;
		f[u][v] = f[v][u] = c;
	}
	fr (i, 1, n)
		nans[i] = i;
	do{
		Ans = max(Ans, calc());
	}while(next_permutation(nans + 1, nans + 1 + n));
	cout << Ans;
}

[AtCoder-abc318_d] [Problem H] 代码源自 CEFqwq​ 许嘉懿 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define R(a) cin >> a
#define P(a) cout << a
int n;
int a[20][20];
int f[200005]; 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	R(n);
	fr (i, 1, n)
		fr (j, i + 1, n)
			R(a[i][j]);
	memset(f, 0, sizeof f);
	fr (S, 0, (1 << n) - 1){
		fr (i, 1, n)
			fr (j, i + 1, n)
				if ((S & ((1 << i - 1) | (1 << j - 1))) == 0)
					f[S | (1 << i - 1) | (1 << j - 1)] = max(f[S | (1 << i - 1) | (1 << j - 1)], f[S] + a[i][j]);
	}
	int ans = 0;
	fr (S, 0, (1 << n) - 1)
		ans = max(ans, f[S]);
	P(ans);
}

[AtCoder-abc317_d] [Problem I] 代码源自 shengzeyu​ 盛泽煜 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
long long n,t1,t2,t3,ans1,ans2,m;
long long pri[150],val[150],cnt=0;
long long f[100001];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld%lld",&t1,&t2,&t3);
		if(t1>t2)ans1+=t3;
		else
		{
			ans2+=t3;
			cnt++;
			pri[cnt]=(t1+t2+1)/2-t1;
			val[cnt]=t3;
		}
	}
	m=(ans1+ans2+1)/2-ans1;
	if(m<=0)
	{
		printf("0");
		return 0;
	}
	memset(f,-1,sizeof(f));
	f[0]=0;
	for(int i=1;i<=cnt;i++)
		for(int j=100000;j>=val[i];j--)
			if(f[j-val[i]]!=-1)
			{
				if(f[j]==-1)f[j]=f[j-val[i]]+pri[i];
				else f[j]=min(f[j],f[j-val[i]]+pri[i]);
			}
	long long ans=-1;
	for(int i=m;i<=100000;i++)
		if(ans==-1||(f[i]<ans&&f[i]!=-1))ans=f[i];
	printf("%lld",ans);
	return 0;
}

[AtCoder-abc317_e] [Problem J] 代码源自 shengzeyu​ 盛泽煜 如有题解疑问可咨询该同学

C++
#include<bits/stdc++.h>
using namespace std;
int n,m,sx,sy,ans;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
char c[2011][2011];
int g[2011][2011];
bool used[2011][2011];
struct point
{
	int x,y,step;
}q[4004004],u,v;
void pre(char t,int i,int j)
{
	if(t=='S')g[i][j]=-1,sx=i,sy=j;
	else if(t=='G')g[i][j]=-2;
	else if(t=='#')g[i][j]=1;
	else
	{
		if(t=='<')
		{
			g[i][j]=1;
			int x=i,y=j-1;
			while(c[x][y]=='.'&&y>=1)g[x][y--]=1;
		}
		else if(t=='>')
		{
			g[i][j]=1;
			int x=i,y=j+1;
			while(c[x][y]=='.'&&y<=m)g[x][y++]=1;
		}
		else if(t=='v')
		{
			g[i][j]=1;
			int x=i+1,y=j;
			while(c[x][y]=='.'&&x<=n)g[x++][y]=1;
		}
		else if(t=='^')
		{
			g[i][j]=1;
			int x=i-1,y=j;
			while(c[x][y]=='.'&&x>=1)g[x--][y]=1;
		}
	}
}
void bfs()
{
	q[1].x=sx,q[1].y=sy,q[1].step=0;
	used[sx][sy]=1;
	int pp=1,qq=1;
	while(pp<=qq)
	{
		u=q[pp++];
		for(int i=0;i<4;i++)
		{
			v.x=u.x+dx[i];
			v.y=u.y+dy[i];
			v.step=u.step+1;
			if(v.x<1||v.x>n||v.y<1||v.y>m)continue;
			if(used[v.x][v.y])continue;
			if(g[v.x][v.y]==-2)
			{
				ans=v.step;
				return;
			}
			if(g[v.x][v.y])continue;
			used[v.x][v.y]=1;
			q[++qq]=v;
		}
	}
	ans=-1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		getchar();
		for(int j=1;j<=m;j++)
			c[i][j]=getchar();
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			pre(c[i][j],i,j);
	bfs();
	printf("%d",ans);
	return 0;
}
原文
抓取于
  1. MassPoint

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  2. MassPoint

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%