CCF201909-2 小明种苹果(续)

在这里插入图片描述

/*
 * CSP
 * 201909-1 小明种苹果*/

#include <stdio.h>
#include <vector>

bool circle[1000] = {false};//判断连续三个true

using namespace std;
vector<vector<int> > tree;
vector<int> preeApple;//每棵树最后剩余的果子
int N;//N:苹果树棵树
int sumApples = 0;
int subTree = 0;//发生掉苹果的树的棵树
int circleNum = 0;

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        vector<int> temp;
        int M = 0;
        scanf("%d", &M);
        for (int j = 0; j < M; j++) {
            int tempNum;
            scanf("%d", &tempNum);
            temp.push_back(tempNum);
        }
        tree.push_back(temp);
    }


    for (int i = 0; i < tree.size(); i++) {
        int tempSumApples = tree[i][0];
        for (int j = 0; j < tree[i].size(); j++) {
            if (j > 0) {
                //判断是否有负数
                if (tree[i][j] <= 0) {
                    tempSumApples += tree[i][j];
                } else if (tree[i][j] < tempSumApples) {
                    //判断是不是真的掉落果子
                    tempSumApples = tree[i][j];
                    circle[i] = true;
                }

            }
        }
        sumApples += tempSumApples;
        if (circle[i])
            subTree++;
    }

    int n = N;
    if (n >= 3)
        for (int i = 0; i < n; i++)
            if (circle[(i - 1 + n) % n] && circle[i] && circle[(i + 1) % n])
            {
                circleNum++;
            }

    printf("%d %d %d\n", sumApples, subTree, circleNum);
    return 0;
}


/*
4
4 74 -7 -12 -5
5 73 -8 -6 59 -4
5 76 -5 -10 60 -2
5 80 -6 -15 59 0

5
4 10 0 9 0
4 10 -2 7 0
2 10 0
4 10 -3 5 0
4 10 -1 8 0

*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

没有胡子的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值