概况(复盘)
- 打完最后的分数是170,三等还差5分
- 除了模板25分是我的锅之外(明明考前还看了的),,
- 还有L1最后一题列标号567没减3扣了2分,L2第二题身份证号码是数字扣了4分。
- 以及改了一个多小时(。。。)L3题目没来得及看
L2-033 简单计算器 (25分)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
int n; cin>>n;
stack<int>s1;
stack<char>s2;
for(int i = 1; i <= n; i++){
int x; cin>>x; s1.push(x);
}
for(int i = 1; i < n; i++){
char ch; cin>>ch; s2.push(ch);
}
while(s1.size()>1){
int n1 = s1.top(); s1.pop();
int n2 = s1.top(); s1.pop();
char op = s2.top(); s2.pop();
if(op=='+')
s1.push(n2+n1);
else if(op=='-')
s1.push(n2-n1);
else if(op=='*')
s1.push(n2*n1);
else{
if(n1==0){
cout<<"ERROR: "<<n2<<"/0\n";
return 0;
}
s1.push(n2/n1);
}
}
cout<<s1.top();
return 0;
}
L2-034 口罩发放 (25分)
#include<bits/stdc++.h>
using namespace std;
struct node{string name, id; int states; int t1, t2;};
bool cmp(node a, node b){return a.t1!=b.t1?a.t1<b.t1:a.t2<b.t2;}
int checkid(string s){
if(s.size() != 18)return 0;
for(int i = 0; i < 18; i++)
if(!isdigit(s[i]))return 0;
return 1;
}
int main(){
int d, p; cin>>d>>p;
map<string,int>mp;
vector<node>ans; set<string>se;
for(int i = 1; i <= d; i++){
int t, c; cin>>t>>c;
vector<node>tmp;
for(int j = 1; j <= t; j++){
string name, id; int states, mm, hh; char ch;
cin>>name>>id>>states>>hh>>ch>>mm;
if(checkid(id)){
tmp.push_back({name,id,states,hh*60+mm,j});
if(states==1 && se.count(id)==0){
ans.push_back({name,id,states,hh*60+mm,j});
se.insert(id);
}
}
}
if(tmp.size()==0 || c==0)continue;
sort(tmp.begin(),tmp.end(), cmp);
for(int j = 0; j < tmp.size() && c; j++){
if(mp.count(tmp[j].id)==0 || mp[tmp[j].id]+p+1<=i){
mp[tmp[j].id] = i;
c--;
cout<<tmp[j].name<<" "<<tmp[j].id<<"\n";
}
}
}
for(int i = 0; i < ans.size(); i++){
cout<<ans[i].name<<" "<<ans[i].id<<"\n";
}
return 0;
}
L2-035 完全二叉树的层序遍历 (25分)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100010;
int n, a[maxn];
int Tree[maxn], r;
void build(int x){
if(x>n)return ;
build(x<<1);
build(x<<1|1);
Tree[x] = a[++r];
}
int main(){
cin>>n;
for(int i = 1; i <= n; i++)
cin>>a[i];
build(1);
for(int i = 1; i <= n; i++){
if(i!=1)cout<<" ";
cout<<Tree[i];
}
return 0;
}
L2-036 网红点打卡攻略 (25分)
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 1e9+10;
const int maxn = 220;
int e[maxn][maxn], vis[maxn];
int main(){
int n, m;
cin>>n>>m;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
e[i][j] = inf;
for(int i = 1; i <= m; i++){
int u, v, w;
cin>>u>>v>>w;
e[u][v] = e[v][u] = w;
}
int k; cin>>k;
int cnt = 0, po = 0, hf = inf;
for(int i = 1; i <= k; i++){
memset(vis,0,sizeof(vis));
int kk; cin>>kk;
int la = 0, tmphf = 0, ok = 1;
for(int j = 1; j <= kk; j++){
int x; cin>>x;
if(e[la][x]!=inf && !vis[x]){
tmphf += e[la][x];
la = x;
vis[x]++;
}else{
ok = 0;
}
}
for(int i = 1; i <= n; i++){
if(vis[i]!=1)ok = 0;
}
if(ok && e[la][0] != inf){
tmphf += e[la][0];
cnt++;
if(tmphf < hf){
hf = tmphf;
po = i;
}
}
}
cout<<cnt<<"\n";
cout<<po<<" "<<hf<<"\n";
return 0;
}