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++;
	}
}
相关推荐
郭涤生6 小时前
The whole book test_《C++20Get the details》_notes
开发语言·c++·笔记·c++20
郭涤生8 小时前
Chapter 6: Concurrency in C++20_《C++20Get the details》_notes
开发语言·c++·笔记·c++20
__lost1 天前
C++20的协程简介
c++20·协程
点云SLAM2 天前
C++20新增内容
c++·算法·c++20·c++ 标准库
oioihoii3 天前
C++20 的新工具:std::midpoint 和 std::lerp
c++20
郭涤生5 天前
Chapter 1: Historical Context_《C++20Get the details》_notes
开发语言·c++20
郭涤生5 天前
Chapter 5: The Standard Library (C++20)_《C++20Get the details》_notes
开发语言·c++·笔记·c++20
oioihoii9 天前
深入解析 C++20 中的 std::bind_front:高效函数绑定与参数前置
java·算法·c++20
oioihoii9 天前
C++20:make_shared_for_overwrite与make_unique_for_overwrite
jvm·算法·c++20