蓝桥双周赛 第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;
}
相关推荐
GalaxyPokemon1 小时前
归并排序:分治思想的高效排序
数据结构·算法·排序算法
ThreeYear_s1 小时前
基于FPGA的PID算法学习———实现PI比例控制算法
学习·算法·fpga开发
Coding小公仔3 小时前
LeetCode 240 搜索二维矩阵 II
算法·leetcode·矩阵
C++chaofan3 小时前
74. 搜索二维矩阵
java·算法·leetcode·矩阵
青小莫4 小时前
数据结构-C语言-链表OJ
c语言·数据结构·链表
Studying 开龙wu4 小时前
机器学习监督学习实战五:六种算法对声呐回波信号进行分类
学习·算法·机器学习
Mi Manchi265 小时前
力扣热题100之二叉树的层序遍历
python·算法·leetcode
wu~9705 小时前
leetcode:42. 接雨水(秒变简单题)
算法·leetcode·职场和发展
曼巴UE55 小时前
UE5 音效系统
c++·游戏·ue5·虚幻·音效