当前位置: 首页> 游戏> 单机 > 珠海百度推广优化_有效果的网站排名_求个没封的网站2022_贵州seo学校

珠海百度推广优化_有效果的网站排名_求个没封的网站2022_贵州seo学校

时间:2025/7/9 0:47:38来源:https://blog.csdn.net/2401_83669813/article/details/146300658 浏览次数:0次
珠海百度推广优化_有效果的网站排名_求个没封的网站2022_贵州seo学校

Tasks - OMRON Corporation Programming Contest 2025 (AtCoder Beginner Contest 397)


本文为 AtCoder Beginner Contest 397 A - D题解

题目A:

代码(C++):

#include <bits/stdc++.h>int main() {double n;std::cin >> n;if (n >= 38.0) {std::cout << 1;} else if (n >= 37.5) {std::cout << 2;} else {std::cout << 3;}
}

题目B:  简单贪心,一次遍历

B - Ticket Gate Log

代码(C++):

#include <bits/stdc++.h>int main() {std::string s;std::cin >> s;int ans = 0;bool f = true;for (int i = 0; i < s.size(); i++) {if (f) {if (i % 2 == 0 && s[i] != 'i' || i % 2 == 1 && s[i] != 'o') {f = !f;ans++;}} else {if (i % 2 == 1 && s[i] != 'i' || i % 2 == 0 && s[i] != 'o') {f = !f;ans++;}}}if ((ans + s.size()) % 2 != 0) {ans++;}std::cout << ans;
}

题目C: 哈希表

C - Variety Split Easy

题目大意:

给你一个数组,把数组分成两个部分,使得数组左边所含有的不同数字个数 + 右边所含有的不同数字个数最大

解题思路:

用两个哈希表mp1, mp2进行模拟即可,mp1先把所有数字添加进去,然后从左到右遍历,mp1减去当前数字,mp2加上当前数字,然后更新答案即可

代码(C++):

#include <bits/stdc++.h>int main() {int n;std::cin >> n;std::vector<int> a(n);std::set<int> st;std::map<int, int> mp;for (int i = 0; i < n; i++) {std::cin >> a[i];mp[a[i]]++;}int ans = 0;for (int i = 0; i < n; i++) {mp[a[i]]--;if (mp[a[i]] == 0) {mp.erase(a[i]);}st.insert(a[i]);ans = std::max(ans, int(st.size() + mp.size()));}std::cout << ans;
}

题目D: 数学推导,枚举优化

题目大意:

给定一个数字n,请你找出两个正整数x, y,满足x * x * x - y * y * y = n

解题思路:

此题我参考jiangly的写法,给出如下详细推导证明:

由上述推导可知,我们可以进行以下枚举:
时间复杂度为O(\sqrt[3]{N}),可以满足题目要求

for (i64 d = 1; d * d * d <= n; d++) {}

现在问题就变成了,如何用这个d和n找出y和x,可以参考下面推导:
​​​、​​​​​

 字写的有点丑,见谅...

代码(C++):

#include <bits/stdc++.h>using i64 = long long;int main() {i64 n;std::cin >> n;for (i64 d = 1; d * d * d <= n; d++) {if (n % d != 0) {continue;}i64 p = n / d - d * d;if (p % 3 != 0) {continue;}p /= 3;i64 y = (std::sqrt(d * d + 4 * p) - d) / 2 + 0.5;if (y <= 0) {continue;}i64 x = y + d;if (__int128(x) * x * x - __int128(y) * y * y == n) {std::cout << x << " " << y;return 0;}}std::cout << -1;
}

关键字:珠海百度推广优化_有效果的网站排名_求个没封的网站2022_贵州seo学校

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: