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++;
	}
}
相关推荐
Shan12053 天前
实例分析:C++20的std::jthread
c++20
charlie1145141913 天前
基于开源项目的现代C++工程实践——OnceCallback 前置知识(下):C++20/23 高级特性
c++·开源·c++20
Hical_W4 天前
Hical 踩坑实录五部曲(二):MSVC / GCC / Clang 三平台 C++20 编译差异
linux·windows·经验分享·嵌入式硬件·macos·开源·c++20
Shan12055 天前
C++20中带有约束条件的new
c++20
Hical_W8 天前
用 Hical + MySQL 5 分钟搭建 CRUD API(C++20 协程版)
数据库·mysql·c++20
Hical_W8 天前
从 io_context 出发,掌握 C++20 协程式异步 I/O,学会 TCP 服务器、定时器和多线程模型,结合 Hical 框架实战解读
服务器·tcp/ip·开源·c++20
c++之路13 天前
C++20概述
java·开发语言·c++20
故事还在继续吗14 天前
C++20关键特性
开发语言·c++·c++20
熊文豪15 天前
FinceptTerminal 深度解析:用 C++20 + Qt6 + Python 打造的开源 Bloomberg 终端
python·开源·c++20·bloomberg·finceptterminal
前进吧-程序员1 个月前
现代 C++ 异步编程:从零实现一个高性能 ThreadPool (C++20 深度实践)
开发语言·c++·c++20