蓝桥杯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;
}
相关推荐
labuladong3 小时前
全新的算法 & Agent 课程页上线
算法·llm·agent
leobertlan4 小时前
好玩系列 | 以简构繁,从把玩一把天平进入信息论和编码
算法
电科_银尘4 小时前
【大模型算法与工程 48】项目实战:可调用、可追踪的大模型问答服务
算法
电科_银尘4 小时前
【大模型算法与工程 47】服务工程:并发、排队、限流与可观测性
算法
西数科技CDRSA5 小时前
BGA封装NAND芯片不识别,Flash Extractor引脚直读还原原始镜像
数据结构·算法·硬件工程
星恒随风5 小时前
C++11 加餐(2)并发支持库——mutex、lock_guard、unique_lock 与死锁问题
开发语言·c++
AvocadoZeroOneOI6 小时前
Kadane 算法(最大子段和)
c++·学习·算法·动态规划
汉克老师8 小时前
GESP六级第二课:森林里的分叉城堡——二叉树的构造与存储
c++·二叉树·树·gesp·小学生·小学生学编程
Lazyafei9 小时前
滑动窗口:扩张与收缩的动态区间
算法