蓝桥杯每日一题2023.10.6

题目描述

门牌制作 - 蓝桥云课 (lanqiao.cn)

题目分析

#include<bits/stdc++.h>
using namespace std;
int ans;
int main()
{
	for(int i = 1; i <= 2020; i ++)
	{
		int x = i;
		while(x)
		{
			int a = x % 10;
			if(a == 2)ans ++;
			x /= 10;
		}
	}
	cout << ans;
	return 0;
}

题目描述

既约分数 - 蓝桥云课 (lanqiao.cn)

题目分析 

我们由题意暴力枚举

#include<bits/stdc++.h>
using namespace std;
long long ans;
long long gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	for(int i = 1; i <= 2020; i ++)
	{
		for(int j = 1; j <= 2020; j ++)
		{
			if(gcd(i, j) == 1)
			{
				ans ++;
			}
		}
	}
	cout << ans;
	return 0;
}

题目描述

 蛇形填数 - 蓝桥云课 (lanqiao.cn)

 题目分析

 观察图片,我们可以将其分为三大类(r为行,c为列, nextpos代表下一个数的位置

1.第一行

①r = 1, c奇数nextpos(r, c + 1)

②r = 1, c偶数nextpos(r + 1, c - 1)

2.第一列

①c = 1, r偶数nextpos(r + 1, c)

②c = 1,r奇数&&r != 1nextpos(r - 1, c + 1)

3.中间

①r != 1, c != 1, r + c 是奇数(r + 1, c - 1)

②r != 1, c != 1, r + c 是偶数(r - 1, c + 1)

对于这种中间情况举几个例子:
5(2, 2) : 2 + 2 = 4

14(2, 4) : 2 + 4 = 6

13(3, 3) : 3 + 3 = 6

12(4, 2) : 4 + 2 = 6

8(2, 3) : 2 + 3 = 5

9(3, 2) : 3 + 2 = 5

18(3, 4) : 3 + 4 = 7

答案 :761

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int ans = 1;
	int r = 1, c = 1;
	while(r != 20 || c != 20)
	{
		if(r == 1)
		{
			if(c & 1)c ++;
			else r ++, c --;
		}
		else if(c == 1)
		{
			if(r % 2 == 0)r ++;
			else r --, c ++;
		}
		else if((r + c) % 2) r ++, c--;
		else r --, c ++;
		ans ++;
	}
	cout << ans;
	return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值