美文网首页
CCF-CSP认证-201909-2小明种苹果(续)

CCF-CSP认证-201909-2小明种苹果(续)

作者: Fgban | 来源:发表于2019-11-19 17:01 被阅读0次

    题解如下:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    
    using namespace std;
    
    
    int n, m;
    int a[10001] = {0};
    bool f[10001] = {false};
    
    bool drop(int index){
        if(index == -1)
            index = n - 1;
        if(index == n)
            index = 0;
        return f[index];
    }
    
    
    int main(){
        int i, j, dropnum = 0, con = 0, temp, sum = 0;
        scanf("%d", &n);
        for(i = 0; i < n; i++){
            scanf("%d", &m);
            for(j = 0; j < m; j++){
                scanf("%d", &temp);
                if(temp <= 0)
                    a[i] += temp;
                else{
                    if(a[i] > temp){
                        if(!f[i]){
                            dropnum++;
                            f[i] = true;
                        }
                        a[i] = temp;
                    }
                    else
                        a[i] = temp;
                }
            }
            sum += a[i];
        }
        
        for(i = 0; i < n; i++){
            if(drop(i-1) && f[i] && drop(i+1))
                con++;
        }
        printf("%d %d %d\n", sum, dropnum, con);
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:CCF-CSP认证-201909-2小明种苹果(续)

          本文链接:https://www.haomeiwen.com/subject/wlkgictx.html