蓝桥杯24省c

cpp 复制代码
#include<iostream>
using namespace std;
int const N = 200005;
int n;
long long t;
int ans = 0;
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> t;
		long long test = 2;
		bool flag = 0;
		if (t == 1)
		{
			ans++;
		}
		while (test <= t)
		{
			if (test == t)
			{
				flag = 1;
				break;
				
			}
			test *= 2;
		}
		if(flag==1)ans++;
	}
	cout << ans << endl;
	return 0;
}
cpp 复制代码
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
struct num
{
	int nums;
	int cirs = 0;
};
vector<num>v;

bool cmp(num num1, num num2)
{
	if (num1.cirs == num2.cirs)
	{
		return num1.nums < num2.nums;
	}
	return num1.cirs < num2.cirs;
}
int main()
{
	cin >> n;
	int t;
	num nu;
	for (int i = 1;i <= n;i++)
	{
		cin >> t;
		nu.cirs = 0;
		nu.nums = t;
		while (t)
		{
			int x = t % 10;
			if (x == 8)
			{
				nu.cirs += 2;
			}
			else if (x == 0 || x == 9 || x == 6 || x == 4)
			{
				nu.cirs += 1;
			}

			t /= 10;
		}
		v.push_back(nu);
	}
	sort(v.begin(), v.end(), cmp);
	for (vector<num>::iterator it = v.begin();it != v.end();it++)
	{
		cout << (*it).nums << " ";
	}
	return 0;
}
cpp 复制代码
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int arr[1000005];
int a[500005];
long long ans = 0;
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		cin >> arr[i];
	}
	for (int i = 1;i <= n / 2;i++)
	{
		a[i] = arr[n - i + 1] - arr[i];
	}
	for (int i = 1;i <= n / 2;i++)
	{
		if (a[i] > 0)
		{
			if (a[i + 1] >= a[i])
			{
				a[i + 1] -= a[i];
			}
			else if (a[i + 1] >= 0)
			{
				a[i + 1] = 0;
			}
			ans += a[i];
		}
		else if (a[i] < 0)
		{
			if (a[i + 1] <= a[i])
			{
				a[i + 1] -= a[i];
			}
			else if (a[i + 1] < 0)
			{
				a[i + 1] = 0;
			}
			ans -= a[i];
		}
	}
	cout << ans << endl;
	return 0;
}
cpp 复制代码
#include<iostream>
using namespace std;
int const N = 3e5 + 5;
int n, m, l[N], r[N],a[N],s[N],sum=0;
int main()
{
	cin >> n >> m;
	for (int i = 1;i <= m;i++)
	{
		cin >> l[i] >> r[i];
		a[l[i]]++;
		a[r[i]+1]--;
	}
	for (int i = 1;i <= n;i++)
	{
		a[i] += a[i - 1];
		if (a[i] == 0)sum++;
		s[i] = s[i - 1] + (a[i] == 1);
	}
	for (int i = 1;i <= m;i++)
	{
		cout << s[r[i]] - s[l[i]-1] + sum << endl;
	}
	return 0;
}
相关推荐
宁静致远20214 分钟前
Ubuntu下的Doxygen+VScode实现C/C++接口文档自动生成
c++·vscode·ubuntu
Bluesonli9 分钟前
第 2 天:创建你的第一个 UE5 C++ 项目!
c++·学习·ue5·虚幻·虚幻引擎·unreal engine
追求源于热爱!27 分钟前
记4(可训练对象+自动求导机制+波士顿房价回归预测
图像处理·人工智能·算法·机器学习·回归
比特在路上31 分钟前
蓝桥杯之c++入门(四)【循环】
c++·职场和发展·蓝桥杯
pay顿1 小时前
C++基础day1
c++·学习·笔试
孤寂码农_defector1 小时前
C++【iostream】数据库的部分函数功能介绍
c++
qq_433618441 小时前
哈夫曼树
数据结构·算法
Icomi_1 小时前
【PyTorch】7.自动微分模块:开启神经网络 “进化之门” 的魔法钥匙
c语言·c++·人工智能·pytorch·python·机器学习·计算机视觉
余辉zmh1 小时前
【贪心算法篇】:“贪心”之旅--算法练习题中的智慧与策略(二)
c++·算法·leetcode·贪心算法
余辉zmh1 小时前
【贪心算法篇】:“贪心”之旅--算法练习题中的智慧与策略(一)
c++·算法·leetcode·贪心算法