欢乐赛#67 题解
2026-02-16 13:32:26
发布于:山东
第一题:
知识点:输入输出
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n / 100;
return 0;
}
时间复杂度:O(1)
空间复杂度:O(1)
第二题
知识点:取余、取最小值
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c;
cin >> n >> a >> b >> c;
cout << min({n % a, n % b, n % c});//新语法,在min函数里加{},可以比较若干个值
return 0;
}
时间复杂度:O(1)
空间复杂度:O(1)
第三题
知识点:格式化输入输出,double,处理边界情况,取平均值
#include<iostream>
#include<climits>
using namespace std;
int s = INT_MAX, x;
int n;
long long sum = 0;
int main() {
cin >> n;
for(int i = 0; i < n; i++) {
cin >> x;
if(s == INT_MAX) {
s = x;
continue;
}
sum += abs(x - s);
s = x;
}
double ave = 1.0 * sum / (n - 1);
printf("%.2lf", ave);
return 0;
}
时间复杂度:O(n)
空间复杂度:O(1)
第四题
知识点:字符,字符排序,结构体,结构体排序,vector(也可以不用,用数组要么开全局,要么赋初值,否则很难处理)
#include<bits/stdc++.h>
using namespace std;
int cnt;
struct code {
char c;
int x, y;
};
vector<code> vec;
bool cmp(code a, code b) {
return a.c < b.c;
}
int main() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
char c;
cin >> c;
if(isupper(c)) {
vec.push_back({c, i, j});
}
}
}
if(vec.size() == 0) cout << "not found";
sort(vec.begin(), vec.end(), cmp);
for(auto C : vec) {
cout << C.c << ' ' << C.x << ' ' << C.y << endl;
}
return 0;
}
时间复杂度:O(nma log a + a)
空间复杂度:O(nm + a)
第五题
知识点:进制转换、贪心
#include<bits/stdc++.h>
using namespace std;
double ten_to_b(int b, long long x) {
int cnt1 = 0, cnt2 = 0;
while(x) {
if(x % b >= 10) cnt1++;
cnt2++;
x /= b;
}
return 1.0 * cnt1 / cnt2;
}
int main() {
int n;
cin >> n;
while(n--) {
long long x;
cin >> x;
if(x == 0) cout << 2 << endl;
else {
if(x < 10) cout << 2 << endl;
else {
double mx = -1;
int ans;
for(int i = 11; i <= 36; i++) {
double v = ten_to_b(i, x);
if(v > mx) {
mx = v;
ans = i;
}
}
cout << ans << endl;
}
}
}
return 0;
}
时间复杂度:O(nx)
空间复杂度:O(1)
第六题
知识点:二分
//下面的注释都是我总结出来的法宝
#include<bits/stdc++.h>
using namespace std;
int n, k, a[103];
bool check(int x) {
long long cnt = 0;
for(int i = 1; i <= n; i++) {
cnt += a[i] / x;
}
return cnt >= k;
}
int main() {
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
int l = 0, r = 1001;
//模板尽量都这样写
while(l < r) {
int mid = (l + r + 1) / 2;//这里加1,else就要减1
if(check(mid)) l = mid;
else r = mid - 1;//这里要是r=mid -> mid = (l + r) / 2
}
cout << l;//求极大值l,求极小值r
return 0;
}
时间复杂度:O(log 1000)
空间复杂度:O(n)
求点赞
谢谢观看!!
第一篇竞赛题解兼第一篇欢乐赛#67题解
全部评论 4
@你好题解我帮您发了
4天前 来自 山东
1逆天,何意味
4天前 来自 重庆
0尖子山
4天前 来自 浙江
0你说得对但是你的题解质量明显不如你好老师
4天前 来自 浙江
0
你的时空复杂度真的对吗、
4天前 来自 浙江
0那你来吧
4天前 来自 山东
0诶我还真写了
4天前 来自 浙江
0你这时间复杂度里的常数是什么
4天前 来自 浙江
0
并非第一篇,第一篇欢乐赛题解是我的
4天前 来自 浙江
0我才是首发
4天前 来自 浙江
0争欢乐赛首发的意何味
4天前 来自 重庆
0)))))
4天前 来自 浙江
0
细节只有代码没有思路
4天前 来自 浙江
0






















有帮助,赞一个