A - 课程报名
模拟
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n,v,m,a;
cin >> n >> v >> m >> a;
int i = 1;
int res = 0;
while(i <= n){
res += v;
if(i % m == 0){
v += a;
}
++i;
}
cout << res << endl;
return 0;
}
B - 期末考试成绩
简单的计算
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int sc = 0;
cin >> sc;
double gpa = 4.0;
if(sc>=90){
gpa = 4.0;
}else if(sc >= 60){
gpa = 4.0 - (90 - sc) * 0.1;
}else{
sc = sqrt(sc) * 10;
if(sc >= 60){
gpa = 4.0 - (90 - sc) * 0.1;
}else{
gpa = 0;
}
}
printf("%.01lf\n",gpa);
return 0;
}
C - 志愿者
结构体排序
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct vool{
int i,t,k,g;
}vs[500010];
bool comp(vool &v1,vool &v2){
if(v1.g != v2.g){
return v1.g > v2.g;
}else{
if(v1.t == v2.t){
return v1.i < v2.i;
}
return v1.t > v2.t;
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for(int i = 1;i<=n;++i){
vs[i].i = i;
cin >> vs[i].t >> vs[i].k;
vs[i].g = vs[i].k * vs[i].t;
}
sort(vs+1,vs+n+1,comp);
for(int i = 1;i<=n;++i){
cout << vs[i].i << " \n"[i==n];
}
return 0;
}
D - 终端
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
string s1,s2,s3;
cin >> n;
vector<string> v;
while(n--){
cin >> s1;
if(s1 == "touch"){
cin >> s2;
if(find(v.begin(),v.end(),s2) == v.end()){
v.push_back(s2);
}
}else if(s1 == "rename"){
cin >> s2 >> s3;
auto it1 = find(v.begin(),v.end(),s2);
auto it2 = find(v.begin(),v.end(),s3);
if(it1 != v.end() && it2 == v.end()){
*it1 = s3;
}
}else if(s1 == "rm"){
cin >> s2;
auto it1 = find(v.begin(),v.end(),s2);
if(it1 != v.end()){
*it1 = "";
}
}else if(s1 == "ls"){
for(auto it = v.begin();it != v.end();++it){
if(*it != ""){
cout << *it << endl;
}
}
}
}
return 0;
}
E - 运气
dfs
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll res = 0;
void dfs(ll val,int i,int n,int k){
if(i > n){
if(val % k == 0){
++res;
}
return;
}
for(int j = 1;j<=6;++j){
dfs(val * 10 + j,i+1,n,k);
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n,k;
res = 0;
cin >> n >> k;
dfs(0,1,n,k);
cout << (res % 1000000007 )<< endl;
return 0;
}