跳转至

CSP-J2023 SD补测

T1 planting

 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
#include <cstdio>
using namespace std;
long long n;
int a[1000009];
long long max(long long a,long long b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}
int main(){
    freopen("planting.in","r",stdin);
    freopen("planting.out","w",stdout);
    scanf("%lld",&n);
    long long max_tree=0;
    for(long long i=1;i<=n;i++){
        long long t1,t2;
        scanf("%lld %lld",&t1,&t2);
        max_tree=max(max_tree,t1);
        max_tree=max(max_tree,t2);
        for(int j=t1;j<=t2;j++){
            a[j]++;
        }
    }
    long long maxx=0;
    for(long long i=1;i<=max_tree;i++){
        maxx=max(maxx,a[i]);
    }
    printf("%lld",maxx);
    fclose(stdin);
    fclose(stdout);
    return 0;
}

T2 banquet

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <cstdio>
#include <iostream>
using namespace std;
int T;
int n,x[100009],t[100009];
int max_p=0;
int max(int a,int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}
double max_d(double a,double b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}
double min_d(double a,double b){
    if(a<b){
        return a;
    }else{
        return b;
    }
}
double abs_d(double abc){
    if(abc<0){
        return -abc;
    }else{
        return abc;
    }
}
double check_time(double place){
    double max_ti=0;
    for(int i=1;i<=n;i++){
        max_ti=max_d(max_ti,abs_d(x[i]-place)+t[i]);
    }
    return max_ti;
}
int main(){
    freopen("banquet.in","r",stdin);
    freopen("banquet.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        max_p=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&x[i]);
            max_p=max(max_p,x[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%d",&t[i]);
        }
        double place_ok=0;
        double max_tti=0x3f3f;
        for(double i=1;i<=max_p+0.1;i+=0.1){
            double temp=check_time(i);
            if(max_tti>=temp){
                max_tti=temp;
                place_ok=i;
            }
        }
        cout<<place_ok<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}

T3 deploy

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <cstdio>
#include <iostream>
using namespace std;
int n,m,top=0,a[1000009];
int bian[1000009][2];
bool is_fa(int now,int ifs){
    if(ifs==1&&now==1){
        return false;
    }
    if(now==1){
        return true;
    }
    for(int i=0;i<top;i++){
        if(bian[i][0]==now&&bian[i][1]!=ifs){
            if(is_fa(bian[i][1],bian[i][0])){
                return true;
            }
        }
        if(bian[i][1]==now&&bian[i][0]!=ifs){
            if(is_fa(bian[i][0],bian[i][1])){
                return true;
            }
        }
    }
    return false;
}
void dfs(int x,int y){
    a[x]+=y;
    for(int i=0;i<top;i++){
        if(bian[i][0]==x){
            if(!is_fa(bian[i][1],x)){
                dfs(bian[i][1],y);
            }
        }
        if(bian[i][1]==x){
            if(!is_fa(bian[i][0],x)){
                dfs(bian[i][0],y);
            }
        }
    }
}
int main(){
    freopen("deploy.in","r",stdin);
    freopen("deploy.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        bian[top][0]=x;
        bian[top++][1]=y;
    }
    cin>>m;
    while(m--){
        int p,x,y;
        cin>>p>>x>>y; 
        if(p==1){
            dfs(x,y);
        }else{
            a[x]+=y;
            for(int i=0;i<top;i++){
                if(bian[i][0]==x){
                    a[bian[i][1]]+=y;
                }
                if(bian[i][1]==x){
                    a[bian[i][0]]+=y;
                }
            }
        }
    }
    int q;cin>>q;
    while(q--){
        int x;cin>>x;
        cout<<a[x]<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}

T4 poetize

 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
#include <cstdio>
#include <iostream>
using namespace std;
int n,x,y,z;
int a[49];
long long ans=0;
bool if_good_hand(){
    for(int i=1;i<=n+1;i++){
        for(int j=1;j<=n+1;j++){
            if(a[j-1]-a[i-1]==x){
                for(int k=1;k<=n+1;k++){
                    if(a[k-1]-a[j-1]==y){
                        for(int l=1;l<=n+1;l++){
                            if(a[l-1]-a[k-1]==z){
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}
int dfs(int now){
    if(now==n){
        if(if_good_hand()){
            ans++;
        }
    }else{
        for(int i=1;i<=10;i++){
            a[now+1]=i+a[now];
            dfs(now+1);
        }
    }
}
int main(){
    freopen("poetize.in","r",stdin);
    freopen("poetize.out","w",stdout);
    cin>>n>>x>>y>>z;
    dfs(0);
    cout<<ans%998244353<<endl;
    fclose(stdin);
    fclose(stdout);
    return 0;
}