山东csp-j2022 试题答案及视频讲解

山东csp-j2022 试题答案及视频讲解

T319771 植树节(planting)山东CSP-J2022 入门组1

题目链接:https://www.luogu.com.cn/problem/T319771

同题目:P2367 语文成绩

https://www.luogu.com.cn/problem/P2367

题目讲解:https://www.bilibili.com/video/BV1LM411s7cG/?spm_id_from=333.999.0.0&vd_source=fa5102b0272af775d3bc4ab69fc72737

 1 #include<iostream>
 2 #include<cmath>
 3 using namespace std;
 4 const int N=1000010;
 5 int n;
 6 int a,b,mmin=N,mmax=0;
 7 int num[N];
 8 int ans=0;
 9 
10 void insert(int x,int y) {
11     num[x]++;
12     num[y+1]--;
13 }
14 
15 int main() {
16     scanf("%d",&n);
17     for(int i=1; i<=n; i++) {
18         scanf("%d %d",&a,&b);
19         insert(a,b);//差分,插入
20         mmin=min(a,mmin);
21         mmax=max(b,mmax);
22     }
23     //计算
24     int t=0;
25     for(int i=mmin; i<=mmax; i++) {
26         t+=num[i];
27         ans=max(t,ans);
28     }
29     printf("%d",ans);
30     return 0;
31 }

 

T319773 宴会(banquet) 山东CSP-J2022 入门组2

题目链接:https://www.luogu.com.cn/problem/T319773

同题目:Meeting on the Line   https://www.luogu.com.cn/problem/CF1730B

题目讲解:https://www.bilibili.com/video/BV1T84y1N7Yd/?spm_id_from=333.999.0.0&vd_source=fa5102b0272af775d3bc4ab69fc72737

 1 #include<iostream>
 2 #include<cmath>
 3 #include<cstring>
 4 using namespace std;
 5 const int N=100010;
 6 int t,n,l=1e8,r=-1e8;
 7 int x[N],ti[N];
 8 int main() {
 9     scanf("%d",&t);
10     while(t--) {
11         memset(x,0,sizeof(x));
12         memset(ti,0,sizeof(ti));
13         l=1e8;
14         r=-1e8;
15         scanf("%d",&n);
16         for(int i=1; i<=n; i++)
17             scanf("%d",&x[i]);
18         for(int i=1; i<=n; i++)
19             scanf("%d",&ti[i]);
20         for(int i=1; i<=n; i++) {
21             int u=x[i]-ti[i];//打扮时间等于左移
22             int v=x[i]+ti[i];//打扮时间等于右移
23             l=min(l,u);
24             r=max(r,v);
25         }
26         //printf("l=%d,r=%d\n",l,r);
27         if((l+r)%2==0) printf("%d\n",(r+l)/2);
28         else printf("%.1lf\n",1.0*(r+l)/2);
29     }
30     return 0;
31 }

T319774 部署(deploy)山东CSP-J2022 入门组3

题目链接:https://www.luogu.com.cn/problem/T319774

题目讲解:https://www.bilibili.com/video/BV11o4y1z7oD/?spm_id_from=333.999.0.0&vd_source=fa5102b0272af775d3bc4ab69fc72737

 1 #include<iostream>
 2 #include<cstring>
 3 using namespace std;
 4 const int N=1000010;
 5 const int M=2*N;
 6 int n,m,p,q;
 7 int a[N];
 8 int h[N],e[M],ne[M],idx;
 9 int b[N],c[N];//差分数组
10 bool st[N];
11 void add(int a, int b) {
12     e[idx] = b;
13     ne[idx] = h[a];
14     h[a] = idx ++ ;
15 }
16 
17 void dfs(int u,int fa) {
18     st[u]=1;
19     b[u]+=b[fa] ;
20     int sum=0;
21     for(int i=h[u]; i!=-1; i=ne[i]) {
22         int v=e[i];
23         if(st[v]==1) continue;
24         sum+=c[v];
25         dfs(v,u);
26     }
27     a[u]+=sum+c[u]+c[fa];
28     a[u]+=b[u];
29     return;
30 }
31 
32 int main() {
33     scanf("%d",&n);
34     for(int i=1; i<=n; ++i) {
35         scanf("%d",&a[i]);
36     }
37     memset(h,-1,sizeof(h));
38     for(int i=1; i<=n-1; ++i) {
39         int u,v;
40         scanf("%d %d",&u,&v);
41         add(u,v);
42         add(v,u);
43     }
44     scanf("%d",&m);
45     for(int i=1; i<=m; ++i) {
46         int op,x,y;
47         scanf("%d %d %d",&op,&x,&y);
48         if(op==1) {
49             b[x]+=y;
50         } else {
51             c[x]+=y;
52         }
53     }
54     dfs(1,0);
55     scanf("%d",&q);
56     while(q--) {
57         int x;
58         scanf("%d",&x);
59         printf("%d\n",a[x]);
60     }
61     return 0;
62 }

 

T319775 吟诗(poetize)山东CSP-J2022 入门组4

同题目:[ARC058E] 和風いろはちゃん  https://www.luogu.com.cn/problem/AT_arc058_c

 

posted @ 2023-03-07 21:38  关于42号星球  阅读(1485)  评论(0编辑  收藏  举报