【每日一题 | 2025】2.24 ~ 3.2

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

文章目录

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

正文

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

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

【AC_Code】

cpp 复制代码
#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】

cpp 复制代码
#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】

cpp 复制代码
#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】

cpp 复制代码
#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】

cpp 复制代码
#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】

cpp 复制代码
#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】

cpp 复制代码
#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;
}

结语

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

相关推荐
GUIQU.22 天前
【每日一题 | 2025】2.3 ~ 2.9
每日一题
极客先躯3 个月前
高级java每日一道面试题-2024年11月27日-JVM篇-JVM的永久代中会发生垃圾回收么?
java·jvm·每日一题·内存溢出·元空间·java高级面试·永久代
凉风听雪4 个月前
VsCode插件:前端每日一题
前端·ide·vscode·每日一题
C_GUIQU4 个月前
【每日一题】24.10.14 - 24.10.20
每日一题
sweetheart7-75 个月前
LeetCode54. 螺旋矩阵(2024秋季每日一题 21)
线性代数·矩阵·力扣·数组·每日一题
sweetheart7-76 个月前
LeetCode152. 乘积最大子数组(2024秋季每日一题 2)
数据结构·算法·动态规划·dp·每日一题
sweetheart7-76 个月前
LeetCode172. 阶乘后的零(2024秋季每日一题 1)
数据结构·算法·leetcode·每日一题·hot100
无名之逆9 个月前
54. 螺旋矩阵【rust题解】
开发语言·前端·算法·rust·力扣·每日一题
菜菜的小彭9 个月前
2024-5-12——吃掉 N 个橘子的最少天数
java·算法·leetcode·面试·职场和发展·每日一题