蓝桥杯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;
}
相关推荐
C++ 老炮儿的技术栈1 小时前
volatile使用场景
linux·服务器·c语言·开发语言·c++
hz_zhangrl1 小时前
CCF-GESP 等级考试 2026年3月认证C++一级真题解析
开发语言·c++·gesp·gesp2026年3月·gespc++一级
Liu628881 小时前
C++中的工厂模式高级应用
开发语言·c++·算法
AI科技星1 小时前
全尺度角速度统一:基于 v ≡ c 的纯推导与验证
c语言·开发语言·人工智能·opencv·算法·机器学习·数据挖掘
波特率1152002 小时前
const关键字与函数的重载
开发语言·c++·函数重载
条tiao条2 小时前
KMP 算法详解:告别暴力匹配,让字符串匹配 “永不回头”
开发语言·算法
干啥啥不行,秃头第一名2 小时前
C++20概念(Concepts)入门指南
开发语言·c++·算法
tobias.b2 小时前
计算机基础知识-数据结构
java·数据结构·考研
zzh940772 小时前
Gemini 3.1 Pro 硬核推理优化剖析:思维织锦、动态计算与国内实测
算法
2301_807367193 小时前
C++中的解释器模式变体
开发语言·c++·算法