C++2025年3月等级考试试题(部分)

cpp 复制代码
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
float a[110]={0};
int n;
float sum;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sum=a[0];
	sort(a+0,a+n);
	for(int i=1;i<n;i++)
	{
		sum=(sum+a[i])/2;
	}
	sum=sum+0.5;
	cout<<(int)sum;
	
	
	return 0;
}
cpp 复制代码
#include<iostream>
#include<algorithm>
using namespace std;
struct s
{
	int v;
	int t;
};
s que[200005]={0};

void func(int);
bool c[200005]={0};
int a,b;
int n;
int main()
{
	cin>>a>>b>>n;
	func(a);
	
	
    return 0;
}
void func(int m)
{
	int head=0;
	int tail=0;
	c[n+100000]=1;
	que[++tail]=s{n,0};
	while(head<tail)
	{
		s h=que[head];
		if(h.v==b)
		{
			cout<<h.t+2;
			break;
		}
		int v=h.v+1;
		int in=v+100000;
		if(in>=0&&in<200005&&c[in]==0)
		{
			que[++tail]=s{v,h.t+1};
			c[in]=1;
		}
		v=h.v-1;
		in=v+100000;
		if(in>=0&&in<200005&&c[in]==0)
		{
			que[++tail]=s{v,h.t+1};
			c[in]=1;
		}
		v=h.v*n;
		in=v+100000;
		if(in>=0&&in<200005&&c[in]==0)
		{
			que[++tail]=s{v,h.t+1};
			c[in]=1;
		}
		head++;
	}
}
相关推荐
楼田莉子4 天前
C++20新特性:协程
开发语言·c++·后端·学习·c++20
ouliten6 天前
C++笔记:C++20风格线程池
c++·笔记·c++20
眠りたいです8 天前
现代C++:C++17中的新库特性
开发语言·c++·c++20·c++17
楼田莉子14 天前
C++20新特性:Range库
开发语言·c++·后端·学习·c++20
楼田莉子15 天前
C++20现代特性:概念与约束
开发语言·c++·后端·学习·c++20
aluluka15 天前
C++ 20 协程的探索
c++·c++20
君鼎19 天前
内存池完整实现——C++20版
c++20·内存池
普通网友1 个月前
记录我适配iOS26遇到的一些问题
c++20
前进吧-程序员1 个月前
C++20/23 Ranges:从「迭代器对」到「可组合管道」
c++20
Shan12051 个月前
实例分析:C++20的std::jthread
c++20