题解
B4074 [CSP-X 2018] 统计成绩
简单枚举+判断题,轻轻松松
for(int i=1;i<=n;i++){
if(a[i] >= 90 && a[i] <= 100)sum1++;
if(a[i] >= 80 && a[i] <= 89)sum2++;
if(a[i] >= 60 && a[i] <= 79)cnt1++;
if(a[i] < 60)cnt2++;
}
B4073 [CSP-X 2018] 快递费用
一道判断+输出题,但我写的代码过于石山了
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
int n,m,cnt1,cnt2,sum1,sum2,ans = 1,q;
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
if(n <= 500){
cout<<20;
return 0;
}
if(n > 500 && m == 1){
int q = n - 500,v = 0;
if(q >= 500){
while(q >= 500){
q -= 500;
v++;
}
}
if(q < 500)v++;
ans = (4 * v) + 20;
cout<<ans;
return 0;
}
if(n > 500 && m == 2){
int q = n - 500,v = 0;
if(q >= 500){
while(q >= 500){
q -= 500;
v++;
}
}
if(q < 500)v++;
ans = (6 * v) + 20;
cout<<ans;
return 0;
}
if(n > 500 && m == 3){
int q = n - 500,v = 0;
if(q >= 500){
while(q >= 500){
q -= 500;
v++;
}
}
if(q < 500)v++;
ans = (9 * v) + 20;
cout<<ans;
return 0;
}
if(n > 500 && m == 4){
int q = n - 500,v = 0;
if(q >= 500){
while(q >= 500){
q -= 500;
v++;
}
}
if(q < 500)v++;
ans = (10 * v) + 20;
cout<<ans;
return 0;
}
if(n > 500 && m == 5){
int q = n - 500,v = 0;
if(q >= 500){
while(q >= 500){
q -= 500;
v++;
}
}
if(q < 500)v++;
ans = (17 * v) + 20;
cout<<ans;
return 0;
}
return 0;
}
P1097 [NOIP 2007 提高组] 统计数字
讲这道题之前,先讲一个内容
map桶
定义:
map<值,类型>变量名
for(auto x : mp)
这个代码的意思等于
for(int x = 1;x <= mp;x++)
可是我们都知道,桶不能这样
所以这个
那我们如何输出呢?
for(auto x : mp){
cout<<x.first<<" "<<x.second;
}
第1位:字符为
第2位:字符为
第3位:字符为
第4位:字符为
第5位:字符为