蓝桥双周赛 第21场 小白入门赛

1 动态密码

思路:可以直接填空也可以写程序

cpp 复制代码
void solve()
{
	int a = 20241111;
	stack<int> stk;
	while(a)
	{
		stk.push(a % 2);
		a /= 2;
	}
	while(stk.size())
	{
		cout << stk.top();
		stk.pop();
	}
  
}

2 购物车里的宝贝

思路:总体异或和为0即可说明可分成一样的两组

cpp 复制代码
int n;
int ans;

void solve()
{
	cin >> n;
	int x;
	for (int i = 1;i <= n;i ++) cin >> x,ans ^= x;
	cout << (ans == 0 ? "YES" : "NO") << endl;
}

4 蓝桥商场

思路:ans累加最大的数需要的步骤数的同时依次减去小的步骤

cpp 复制代码
const int N = 1e5 + 9; 

int n;
LL ans;
int a[N];

void solve()
{
	// 30201 2*n - 1 
	// 2 2 2  (6)
	// 3 3 3 
	cin >> n;
	for (int i = 1;i <= n;i ++) cin >> a[i]; 
	sort(a + 1,a + 1 + n);
	
	for (int i = 1,j = n;i <= j;j--)
	{
		// cout << j << "-" << endl;
		LL tmp = 2 * a[j] - 1;
		ans += tmp;
		while(2 * a[i] - 1 <= tmp)
		{
			tmp -= 2 * a[i] - 1;
			i ++;
		}
	}
	
	cout << ans << endl; 
	
	
	
}

6 薅羊毛

思路:相邻两个数的gcd为1,相邻两个数的幂的gcd也为1

cpp 复制代码
const int p = 1e9 + 7;

LL L,R;

LL qmi(LL a,LL b)
{
	LL ans = 1;
	while(b)
	{
		if (b & 1) ans = ans * a % p;
		a = a * a % p;b >>= 1;
	}
	return ans;
} 

void solve()
{

	cin >> L >> R;
	LL ans = 0;
	for (int i = L;i < R;i ++)
	{
		LL a = qmi(i,i);
		LL b = qmi(i + 1,i + 1);
		LL val = (a * b % p) ;
		ans = (ans + val) % p;
	}
	cout << ans << endl;
}
相关推荐
郝学胜-神的一滴2 分钟前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
Lucas. Wáng3 小时前
Qt学习之旅
c++·qt
星恒随风3 小时前
从0实现C++ AI大模型接入SDK(二):AI知识科普——从图灵测试到ChatGPT,人工智能的发展历程
linux·c++·人工智能·笔记·chatgpt
青少儿编程课堂3 小时前
蓝桥杯真题解析:三维偏序的CDQ分治(全国青少年信息素养大赛与电子学会编程考级)
c++·python·算法·bfs·信息学竞赛
Navigator_Z3 小时前
LeetCode //C - 1323. Maximum 69 Number
c语言·算法·leetcode
geovindu4 小时前
python:Lasso
开发语言·后端·python·算法
AAA修煤气灶刘哥5 小时前
同一个模型,为什么还要专门练一遍怎么用工具?
人工智能·后端·算法
csdn_aspnet5 小时前
C++ 求给定点集的简单闭合路径(Find Simple Closed Path for a given set of points)
c++
艾莉丝努力练剑5 小时前
【AI接入大模型SDK】解决接口连接异常问题
前端·c++·人工智能·学习·ai·架构
Severus_black5 小时前
【C++初阶】模板进阶
c语言·c++·学习