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++;
	}
}
相关推荐
小葡萄202516 小时前
黑马程序员c++2024版笔记 第一章 变量和基本类型
笔记·c++20
xiaolang_8616_wjl13 天前
c++_2011 NOIP 普及组 (1)
开发语言·数据结构·c++·算法·c++20
C咖咖15 天前
C++20 小语法
c++20
郭涤生23 天前
Concepts (C++20)
c++20
chendilincd25 天前
C++ 的史诗级进化:从C++98到C++20
java·c++·c++20
oioihoii1 个月前
C++20 统一容器擦除:std::erase 和 std::erase_if
c++20
郭涤生1 个月前
The whole book test_《C++20Get the details》_notes
开发语言·c++·笔记·c++20
郭涤生1 个月前
Chapter 6: Concurrency in C++20_《C++20Get the details》_notes
开发语言·c++·笔记·c++20
__lost1 个月前
C++20的协程简介
c++20·协程