跳到正文

个人记录

8.3课堂总结

chengcheng_2015约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟

版本

  1. v1当前

常用函数专题

C++
setw(x)
floor()
ceil()
sqrt()
max(a,b)
min(a,b)
fixed setprecision(x)
swap(a,b)
round()
abs()

课堂总结:

B2066 救援

代码思路:

代码
算出每一个屋顶的时间
//sqrt(x*x+y*y)/50*2+r*1.5
求和 再向上取整

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int n;
double v=0;
int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        double x, y, r;
        cin >> x >> y >> r;
        v += sqrt(x*x+y*y)/50*2+r*1.5;
    }
    cout << (int)ceil(v);
    return 0;
}

B2108 图像模糊处理

代码思路:

代码
如果是周围的 直接输出
如果是不周围的 输出四舍五入的平均值

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
double a[105][105];
int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(i==1||i==n||j==1||j==m) cout << a[i][j] << ' ';
            else cout << round((a[i][j] + a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1])/5) << ' ';
        }
        cout << "\n";
    }
    return 0;
}

P1090 [NOIP 2004 提高组] 合并果子

代码思路:

代码
用一个优先队列来存储
用一个变量来计算体力sum
取出前面两个数a,b
sum 加 a 和 b
把a+b放入队列

正确代码:

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, v=0;
    cin >> n;
    priority_queue<int,vector<int>,greater<int>>q;
    while(n--){
        int x;
        cin >> x;
        q.push(x);
    }
    while(q.size()>1){
        int a=q.top();
        q.pop();
        int b=q.top();
        q.pop();
        v += a+b;
        q.push(a+b);
    }
    cout << v;
    return 0;
}
原文