官方题解|欢乐赛47题解
2025-05-14 10:34:36
发布于:浙江
欢乐赛47题解
T1
题意分析
本题考查输入输出,每天喝两瓶, 天喝 瓶,直接输出 即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
cout << n * 2 << endl;
return 0;
}
T2
题解分析
本题考查循环结构,可以看出,每天喝的可乐数目喝天数一样,可以通过 for
循环依次枚举每一天喝的可乐数目,直接加起来即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int ans = 0;
for(int i = 1; i <= n; i ++ ){
ans += i;
}
cout << ans << endl;
return 0;
}
T3
题意分析
本题考查双重循环,第一层循环按学号枚举每一个同学,第二层循环枚举天数,学号为 的同学,在第 天喝的可乐数目是 。
代码
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i ++ ){
for(int j = 1; j <= n; j ++ ){
cout << i * j << ' ';
}
cout << endl;
}
return 0;
}
T4
题意分析
本题只要用 向上取整函数模拟出这个式子,也可以用向上取整的特性,进行if-else判断模拟。可以采用函数的思想,把相同的一些步骤封装起来,具体见代码。
代码
#include <bits/stdc++.h>
using namespace std;
int get(int a, int b, int c, int d){
int x = (a + b + c) / d;
if((a + b + c) % d) x ++;
return x;
}
int main(){
int x, y, z;
cin >> x >> y >> z;
cout << get(get(x, y, z, 3), get(3 * x, 5 * y, 7 * z, 4), get(11 * x, 13 * y, 17 * z, 5), 7);
}
T5
题意分析
本题题意稍微复杂一点: 具体的意思是,你可以魄袭敌人的手牌,下 张不同花色的牌,根据敌人和自己的手牌数弃置数目的不同从而达到某种效果,题目问的是指定的 个效果是否能达到,如果达到了输出 ,达不到输出 ,简单分类讨论即可。
代码
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n, m;
string s1, s2;
cin >> n >> m >> s1 >> s2;
bool a1 = 0, b1 = 0, c1 = 0, d1 = 0, a2 = 0, b2 = 0, c2 = 0, d2 = 0;
for(auto it : s1){
if(it == 'a') a1 = 1;
if(it == 'b') b1 = 1;
if(it == 'c') c1 = 1;
if(it == 'd') d1 = 1;
}
for(auto it : s2){
if(it == 'a') a2 = 1;
if(it == 'b') b2 = 1;
if(it == 'c') c2 = 1;
if(it == 'd') d2 = 1;
}
int ans[10] = {0};
if(a2 && b2 && c2 && d2) ans[1] = 1;
if((a2 && b2 && c2 && d1) || (a2 && b2 && d2 && c1) || (a2 && c2 && d2 && b1) || (b2 && c2 && d2 && a1)) ans[2] = 1;
if((a1 && b1 && c1 && d2) || (a1 && b1 && d1 && c2) || (a1 && c1 && d1 && b2) || (b1 && c1 && d1 && a2)) ans[3] = 1;
if(a1 && b1 && c1 && d1) ans[4] = 1;
for(int i = 1; i <= 4; i ++ ){
cout << ans[i];
}
cout << endl;
}
int main(){
int t;
cin >> t;
while(t -- ){
solve();
}
return 0;
}
T6
题意分析
本题是求 到 中,至少有 个质因子的数的个数。可以在埃氏筛法的过程中,不断对每个数求其质因子的个数,最后枚举一下每一个数是否满足有大于等于 个质因子即可。
代码
/*
对艾氏筛法的理解
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 10000000;
int a[N], n, m, k, cnt, primes[M + 10];
int st[M + 10];
void get_primes(int n)
{
for (int i = 2; i <= n; i ++ )
{
if(!st[i]){
for(int j = i; j <= n; j += i){
st[j] ++;
}
}
}
}
int main(){
int n, k;
cin >> n >> k;
get_primes(n);
for(int i = 1; i <= n; i ++ ){
if(st[i] >= k){
cnt ++;
}
}
cout << cnt;
return 0;
}
全部评论 1
老师怎么又发到灌水池塘里力
2025-05-14 来自 北京
1不懂啊,下次你来写,你来发
2025-05-14 来自 浙江
0啊???
2025-05-15 来自 北京
0支持支持
2025-05-16 来自 广东
0
有帮助,赞一个