当前位置: 首页 > news >正文

【每日一题 | 2025】2.24 ~ 3.2

在这里插入图片描述

个人主页:Guiat
归属专栏:每日一题

在这里插入图片描述

文章目录

  • 1. 【2.24】P10424 [蓝桥杯 2024 省 B] 好数
  • 2. 【2.25】P8665 [蓝桥杯 2018 省 A] 航班时间
  • 3. 【2.26】P10905 [蓝桥杯 2024 省 C] 回文字符串
  • 4. 【2.27】P10425 [蓝桥杯 2024 省 B] R 格式
  • 5. 【2.28】P10426 [蓝桥杯 2024 省 B] 宝石组合
  • 6. 【3.1】P10912 [蓝桥杯 2024 国 B] 数星星
  • 7. 【3.2】P10914 [蓝桥杯 2024 国 B] 跳石头

正文

1. 【2.24】P10424 [蓝桥杯 2024 省 B] 好数

题目链接:https://www.luogu.com.cn/problem/P10424

【AC_Code】

#include <iostream>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int N, cnt;

bool check(int n)
{
	int number = 1;
	while (n > 0)
	{
		if (number % 2 == 1) { if ((n % 10) % 2 == 0) return false; }
		else if ((n % 10) % 2 != 0) return false;
		n /= 10; number ++;
	}
	return true;
}

int main()
{
	IOS; cin >> N;
	for (int i = 1; i <= N; i ++) if (check(i)) cnt ++;
	cout << cnt << '\n';
	
	return 0;
}

2. 【2.25】P8665 [蓝桥杯 2018 省 A] 航班时间

题目链接:https://www.luogu.com.cn/problem/P8665

【AC_Code】

#include <iostream>
#include <iomanip>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int solve()
{
	int h1, m1, s1, h2, m2, s2, d = 0; char c1, c2, c3, c4, c5, c6;
	cin >> h1 >> c1 >> m1 >> c2 >> s1 >> h2 >> c3 >> m2 >> c4 >> s2;
	if (cin.peek() == ' ') cin >> c5 >> d >> c6;
	return (86400 * d + 3600 * h2 + 60 * m2 + s2) - (3600 * h1 + 60 * m1 + s1);
}

int main()
{
	IOS; int T; cin >> T;
	while (T --)
	{
		int ans = (solve() + solve()) >> 1;
		cout << setw(2) << setfill('0') << ans / 3600 << ':'
			 << setw(2) << setfill('0') << (ans % 3600) / 60 << ':'
			 << setw(2) << setfill('0') << ans % 60 << '\n';
	}
	
	return 0;
}

3. 【2.26】P10905 [蓝桥杯 2024 省 C] 回文字符串

题目链接:https://www.luogu.com.cn/problem/P10905

【AC_Code】

#include <iostream>
#include <string>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve()
{
    string s; cin >> s; int l = 0, r = s.length() - 1;
    while (s[l] == 'l' || s[l] == 'q' || s[l] == 'b') l ++;
    while (s[r] == 'l' || s[r] == 'q' || s[r] == 'b') r --;
    bool flag = true;
    for (int i = l, j = 0; i <= (l + r) / 2; i ++, j ++) if (s[i] != s[r - j]) flag = false;
    if ( ! flag ) cout << "No\n";
    else if (l == 0) cout << "Yes\n";
    else if (r == s.length() - 1) cout << "No\n";
    else if (s.length() - r < l) cout << "No\n";
    else
	{
        l --; r ++;
        while (s[l] == s[r] && l >= 0 && r <= s.length()) l --, r ++;
        if (r == s.length() || l == -1) cout << "Yes\n";
        else cout << "No\n";
    }
}

int main()
{
    IOS; int T; cin >> T; while (T--) solve();
    
    return 0;
}

4. 【2.27】P10425 [蓝桥杯 2024 省 B] R 格式

题目链接:https://www.luogu.com.cn/problem/P10425

【AC_Code】

#include <iostream>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e6;
int n, a[N], pos, len; string q;

void solve()
{
	reverse(q.begin(), q.end());
	pos = q.find('.'); q.erase(pos, 1); len = q.size();
	for (int i = 0; i < len; i ++) a[i + 1] = q[i] - '0';
	for (int i = 1; i <= n; i ++)
	{
		for (int i = 1; i <= len; i ++) a[i] *= 2;
		for (int i = 1; i <= len; i ++) a[i + 1] += a[i] / 10, a[i] %= 10;
		if (a[len + 1]) len ++;
	}
	if (a[pos] >= 5) a[pos + 1] ++;
	for (int i = pos + 1; i <= len; i ++) a[i + 1] += a[i] / 10, a[i] %= 10;
	if (a[len + 1]) len ++;
	for (int i = len; i > pos; i --) cout << a[i]; cout << '\n';
}

int main()
{
	IOS; cin >> n >> q; solve();
	
	return 0;
}

5. 【2.28】P10426 [蓝桥杯 2024 省 B] 宝石组合

题目链接:https://www.luogu.com.cn/problem/P10426

【AC_Code】

#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int MAXN = 1e5 + 10; int n, h[MAXN]; vector<int> fac[MAXN];

int gcd(int a, int b) { return __gcd(a, b); }

void solve()
{
    cin >> n; for (int i = 1; i <= n; ++ i) cin >> h[i];
    sort(h + 1, h + 1 + n);
    for (int i = 1; i <= n; ++ i) for (int j = 1; j * j <= h[i]; ++j)
	{
        if (h[i] % j == 0)
		{
            fac[j].push_back(h[i]);
            if (h[i] / j != j) fac[h[i] / j].push_back(h[i]);
        }
    }
    for (int i = MAXN; i >= 1; -- i)
	{
        if (fac[i].size() >= 3)
		{
            int a = fac[i][0], b = fac[i][1], c = fac[i][2];
            if (gcd(gcd(a, b), c) == i) { cout << a << " " << b << " " << c << "\n"; return; }
        }
    }
}

int main()
{
    IOS; solve();

    return 0;
}

6. 【3.1】P10912 [蓝桥杯 2024 国 B] 数星星

题目链接:https://www.luogu.com.cn/problem/P10912

【AC_Code】

#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e5 + 10, mod = 1e9 + 7;
int n, a[N], b[N], c[N], f[N], l, r, ans;
vector<int> vec[N];

int fun(int x, int y) { return 1ll * b[x] * f[y] % mod * f[x - y] % mod; }

void DFS(int x, int y)
{
	for (auto n : vec[x]) if (n != y) DFS(n, x);
	if (static_cast<int> (vec[x].size()) + 1 >= 1)
	{
		int p = min(r - 1, static_cast<int> (vec[x].size()));
		for (int i = l - 1; i <= p; i ++) ans = (ans + fun(vec[x].size(), i)) % mod;
	}
}

void solve()
{
	cin >> n; b[0] = c[0] = 1; b[1] = 1; c[1] = 1; f[0] = 1; f[1] = 1;
	for (int i = 2; i <= n; i ++)
	{
		b[i] = 1ll * b[i - 1] * i % mod;
		c[i] = 1ll * c[mod % i] * (mod - mod / i) % mod;
		f[i] = 1ll * f[i - 1] * c[i] % mod;
	}
	for (int i = 1; i < n; i ++)
	{
		int x, y; cin >> x >> y;
		vec[x].push_back(y); vec[y].push_back(x);
	}
	cin >> l >> r;
	DFS(1, 0);
	cout << ans << '\n';
}

int main()
{
	IOS; solve();
	
	return 0;
}

7. 【3.2】P10914 [蓝桥杯 2024 国 B] 跳石头

题目链接:https://www.luogu.com.cn/problem/P10914

【AC_Code】

#include <iostream>
#include <bitset>
#define IOS ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); 

using namespace std;

const int N = 4e4 + 10; int c[N], n, ans;
bitset<N> f[N];

void solve()
{
	cin >> n;
	for (int i = 1; i <= n; i ++)
	{
		cin >> c[i]; f[i][c[i]] = 1;
	}
	for (int i = n; i >= 1; i --)
	{
		if (i + c[i] <= n) f[i] |= f[i + c[i]];
		if (2 * i <= n) f[i] |= f[2 * i];
		ans = max(ans, (int)f[i].count());
	}
	cout << ans << '\n';
}

int main()
{
	IOS; solve();
	
	return 0;
}

结语
感谢您的阅读!期待您的一键三连!欢迎指正!

在这里插入图片描述

相关文章:

  • 题解 | 牛客周赛82 Java ABCDEF
  • Cargo, the Rust package manager, is not installed or is not on PATH.
  • 基于机器学习的图像分类综述
  • 【0005】Python变量详解
  • 【Vue CLI脚手架开发】——1.Vue脚手架的安装与使用
  • 【Maven】基于IDEA进行Maven工程的创建、构建
  • 蓝桥杯2024年真题java B组 【H.拼十字】
  • 【Python 数据结构 3.顺序表】
  • windows下玩转vllm:在wsl下安装vllm后续,设置modelscope作为下载源
  • 蓝桥杯---归并排序算法题目(leetcode第912题)
  • 《Python百练成仙》31-40章(不定时更新)
  • springboot之集成Elasticsearch
  • 机器学习的起点:线性回归Linear Regression
  • 项目准备(flask+pyhon+MachineLearning)- 2
  • 计算机毕业设计SpringBoot+Vue.js教学辅助平台(源码+文档+PPT+讲解)
  • MySQL初学之旅(5)详解查询
  • Spring AI:开启Java开发的智能新时代
  • next实现原理
  • 代码随想录算法营Day51 | 647. 回文子串,516. 最长回文子序列
  • 【极客时间】浏览器工作原理与实践-2 宏观视角下的浏览器 (6讲) - 2.3 HTTP请求流程:为什么很多站点第二次打开速度会很快?
  • 上海市重大工程一季度开局良好,多项生态类项目按计划实施
  • 终于越过萨巴伦卡这座高山,郑钦文感谢自己的耐心和专注
  • 商务部新闻发言人就暂停17家美国实体不可靠实体清单措施答记者问
  • 4月企业新发放贷款利率处于历史低位
  • 男子入户强奸高龄独居妇女致其死亡,法院:属实,已执行死刑
  • 江西贵溪:铜板上雕出的国潮美学