蓝桥杯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;
}
相关推荐
地平线开发者2 小时前
ReID/OSNet 算法模型量化转换实践
算法·自动驾驶
快乐的划水a2 小时前
组合模式及优化
c++·设计模式·组合模式
地平线开发者2 小时前
开发者说|EmbodiedGen:为具身智能打造可交互3D世界生成引擎
算法·自动驾驶
星星火柴9363 小时前
关于“双指针法“的总结
数据结构·c++·笔记·学习·算法
艾莉丝努力练剑4 小时前
【洛谷刷题】用C语言和C++做一些入门题,练习洛谷IDE模式:分支机构(一)
c语言·开发语言·数据结构·c++·学习·算法
闪电麦坤955 小时前
数据结构:迭代方法(Iteration)实现树的遍历
数据结构·二叉树·
C++、Java和Python的菜鸟6 小时前
第六章 统计初步
算法·机器学习·概率论
Cx330❀6 小时前
【数据结构初阶】--排序(五):计数排序,排序算法复杂度对比和稳定性分析
c语言·数据结构·经验分享·笔记·算法·排序算法
散1126 小时前
01数据结构-Prim算法
数据结构·算法·图论
起个昵称吧6 小时前
线程相关编程、线程间通信、互斥锁
linux·算法