2020团体程序设计天梯赛】L2部分(PTA,L2-033到L2-036)题解代码&复盘

网友投稿 562 2022-05-29

打完最后的分数是170,三等还差5分

除了模板25分是我的锅之外(明明考前还看了的),,

还有L1最后一题列标号567没减3扣了2分,L2第二题身份证号码是数字扣了4分。

以及改了一个多小时(。。。)L3题目没来得及看

//开两个栈直接模拟 #include using namespace std; typedef long long LL; int main(){ int n; cin>>n; stacks1; stacks2; 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: "<

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

//+ 在D天里发口罩,每个人获得要间隔P天。 //+ 给出每天的申请记录和口罩供应,包括string,id,siates,time;按照先后顺序判断每天发给谁。 //+ 并统计状态出问题的人,汇总输出。 //+ 直接模拟即可。能获得口罩的人,P天内没拿过,并且每天排名前几个。 #include 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>d>>p; mapmp;//相隔天数 vectorans; setse;//生病的人 for(int i = 1; i <= d; i++){ int t, c; cin>>t>>c; vectortmp; 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<

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

【2020团体程序设计天梯赛】L2部分(PTA,L2-033到L2-036)题解代码&amp;复盘

37

38

39

40

41

42

43

44

45

46

47

48

49

//满二叉树后序转先序,输出层次遍历 #include 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<

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

//+ n个点m条带权边。给出k条路径,判断能否从v1出发经过每个点一次并返回v1,输出最短的路径。 //+ n<200 所以邻接矩阵存个图,直接暴力枚举就行。 #include 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]){ //cout<

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

二叉树

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Docker初识到使用
下一篇:【IoT美学】鲲鹏——如何正确的购买鲲鹏云服务器?(二)
相关文章