中国传媒大学程序设计大赛2023记录
来源:华佗健康网
A :ACM
首先判断n是否为0,如果n=0,那么直接输出0。否则,输出.再输出后面的0
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==0) cout<<0.0<<endl;
else{
cout<<0<<".";
for(int i=0;i<n;i++){
cout<<0;
}
}
return 0;
}
B:贪吃的Diana
使用map<int,int>first为第几天,second为当天吃的饱腹度
从第一天开始判断,如果改天总共的饱腹度<k,说明不开心
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll> m;//first为第几天 second为点的数量
int main(){
int n,k,s;
cin>>n>>k>>s;
for(int i=0;i<s;i++){
ll a,b;
cin>>a>>b;
m[a]+=b;
}
ll ans=0;
for(int i=1;i<=n;i++){
if(m[i]<k) ans++;
}
cout<<ans<<endl;
return 0;
}
D:穿袜子
保证最少取出多少只袜子才能保证凑齐至少一对(说明是最坏情况下需要取多少只)
对于该样例,最坏的情况下,取7只L 0 1只* 1 最后取一只R 0,即可满足配对成功。
所以需要将所有的袜子类型记录,然后遍历袜子类型,如果左脚中没有该类型并且右脚也没有,那么只取它的一支 如果左脚或右脚有,那么取最大的那个 最后判断如果把所有袜子取走,说明此时没有符合条件的,输出-1 ,否则,输出ans+1
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define ll long long
#define MAX 100000
#define mod 10000007
#define x first
#define y second
using namespace std;
set<int> type;//存放的是所有袜子的类型
map<int, int> mp[3];//mp[0][i]表示左脚类型i有mp[0][i]只 mp[1][] mp[2][]
unordered_map<char, int> m = { {'L',0},{'R',1},{'*',2} };
void solve() {
int n; cin >> n;
int P, M;
char Q;
ll ans = 0, cnt = 0;
while (n--) {
cin >> P >> Q >> M;
type.insert(P);
cnt += M;
mp[m[Q]][P] = M;
}
for (auto x : type) {
if (mp[0][x] + mp[1][x] == 0) {
ans += 1;
}
else {
ans += max(mp[0][x], mp[1][x]);
}
}
if (cnt == ans) cout << -1 << endl;//如果所有的取完,说明没有
else cout << ans + 1 << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cout.tie(0);
solve();
system("pause");
return 0;
}
因篇幅问题不能全部显示,请点此查看更多更全内容