很(不)温馨提示:这不是提示。
这我乱写的。
常有函数:
右对齐占x个字符宽度:
setw(x)向下取整函数:
floor();向上取整函数:
ceil();开根号函数:
sqrt();取a,b两者的最大值:
max(a,b);取a,b两者的最小值:
min(a,b);保留两位小数:
cout << fixed << setprecision(2) << a;交换a,b两者的值:
swap(a,b);四舍五入函数:
round();取x的绝对值:
abs(x);🍬终结:
B2066 救援(题目作者:信息学奥赛一本通 题目难度:入门):
- ❌原因:没看题。
- ❌代码:没写。
- 靠差只是·:开根号函数,向上取整函数。
- 解题死路:大本营距离每个房顶的距离是,速度是,要来回,,每个人上下船的时间。
- ✔️代码:
#include<bits/stdc++.h>
using namespace std;
int a[105][105];
int main(){
double sum = 0;
int n;
cin >> n;
for (int i = 1;i <= n;i++){
double a,s;
int d;
cin >> a >> s;
cin >> d;
sum += sqrt(a*a+s*s)/50*2+1.5*d;
}
cout << (int)ceil(sum);
return 0;
}P8813 [CSP-J 2022] 乘方(题目作者:CCF_NOI 题目难度:入门):
- ❌原因:没判断的情况。
- ❌代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b;
cin >> a >> b;
long long sum = a;
for (long long i = 2;i <= b;i++){
sum *= a;
if (sum > 1e9){
cout << "-1";
return 0;
}
}
cout << sum;
return 0;
}- 考察知识点:I don’t no.
- 解题死路:先判断a是否的情况,否则按照for循环来做。
- ✔️代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
long long a,b,sum=1;
cin >> a >> b;
if (a == 1){ //判断a等于1的情况(因为1乘以什么数都等于1)。
cout << "1"; //是就直接输出1.
return 0;
}
for (long long i = 1;i <= b;i++){
sum *= a;
if (sum > 1e9){ //判断sum是否大于1e9。
cout << "-1"; //大于1e9直接输出-1。
return 0;
}
}
cout << sum;
return 0;
}B2108 图像模糊处理(题目作者:信息学奥赛一本通 题目难度:入门):
- ❌原因:不会四舍五入。
- ❌代码:不知道。
- 考察知识点:四舍五入函数。
- 解题死路:看代码。
- ✔️代码:
#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-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1]+a[i][j])/5) << " "; //那上下左右和自己的和➗5,并用四舍五入函数。
}
}
cout << endl;
}
return 0;
}P9581 「MXOI Round 1」宝箱(题目作者:Coffee_zzz 题目难度:入门):
- ❌原因:代码错了。
- ❌代码:不想放出来。
- 考察知识点:最小值函数。
- 解题死路:先移到最近的宝箱,在移到另外一个宝箱的位置。
- ✔️代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
cout << min(abs(a),abs(b))+abs(a-b);
return 0;
}P1090 [NOIP 2004 提高组] 合并果子(题目作者CCF_NOI 题目难度:普及/提高-):
- ❌原因:新知识点。
- ❌代码:不知道。
- 考察知识点:优先队列(堆)。
- 解题死路:先取队列的第一项,在弹出,在取出第一项,在弹出,答案+=a+b,再输入a+b。
- ✔️代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,sum=0,a,b;
cin >> n;
priority_queue<int,vector<int>,greater<int>>q;
while(n--){
int x;
cin >> x;
q.push(x);
}
while(q.size() > 1){
a = q.top();
q.pop();
b = q.top();
q.pop();
sum += a+b;
q.push(a+b);
}
cout << sum;
return 0;
}- d
- d
- d
- d
- d
- d
- s
- sd
- a
- b
- c
- d
- e
- f
- g
- h
- i
- j
- k
- l
- m
- n
- o
- p
- q
- r
- s
- t
- u
- v
- w
- x
- y
- z
- n
- f
- d
- d
- s
- g
- g
- h
- gd
- s
- th
- fd
- onej
- j
- h
- g
- g
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- y
- jj
- j
- j
- j
- j
- j
- jj
- j
- f
- f
- c
- vg
- g
- f
- e
- r
- y
- v
- s
- fg
- d
- f
- g
- c
- d
- f
- f
