蓝桥双周赛 第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;
}
相关推荐
.千余14 分钟前
【C++】手写双向链表:list容器模拟实现
开发语言·c++·笔记·学习·其他
QuZero19 分钟前
Guava Cache Deep Dive
java·后端·算法·guava
随意起个昵称25 分钟前
线性dp-LIS题目4(A Twisty Movement)
算法·动态规划
liulilittle35 分钟前
过冲:拥塞控制的呼吸与盲行
linux·网络·c++·tcp/ip·计算机网络·tcp·通信
Felven35 分钟前
B. Fair Numbers
数据结构·算法
人道领域39 分钟前
【LeetCode刷题日记】93.复原IP地址
java·开发语言·算法·leetcode
jarreyer1 小时前
【算法记录1】模型训练问题
算法
Felven1 小时前
D. Friends and the Restaurant
算法
想吃火锅10051 小时前
【leetcode】165.比较版本号js
javascript·算法·leetcode
San813_LDD1 小时前
[量化]《浮点数比较的艺术:从内存布局到极致性能优化》
网络·算法