第17次CCF CSP认证第二题:小明种苹果(续)

小明种苹果(续)
第二题在第一题的基础上,加上了苹果自动掉落的情况。采用一个bool型数组记录即可。

#include<iostream>
#include<vector>
using namespace std;

int main()
{
    long long N = 0;
    long long D = 0, E = 0;
    cin>>N;
    vector<bool> isAutoDown;
    long long total = 0;
    long long Count = 0, thisTreeNum = 0, opera = 0;
    long long operaNum = 0;
    for(int i = 0; i < N; i++) {
        cin>>Count;
        operaNum = 0;
        for(int j = 0; j < Count; j++) {
            if(j == 0) {
                cin>>thisTreeNum;
                isAutoDown.push_back(false);
            }
            else {
                cin>>opera;
                if(opera <= 0) {
                    operaNum += opera;
                }
                else {
                    if(thisTreeNum + operaNum != opera) {
                        isAutoDown[i] = true;
                    }
                    thisTreeNum = opera;
                    operaNum = 0;
                }
            }
        }
        thisTreeNum += operaNum;
        total += thisTreeNum;
    }
    for(int i = 0; i < N; i++) {
        if(isAutoDown[i]) {
            D++;
        }
    }
    for(int i = 0; i < N; i++) {
        if(isAutoDown[i] == true) {
            if(i == 0) {
                if(isAutoDown[1] == true && isAutoDown[N-1] == true) {
                    E++;
                }
            }
            else if(i == N - 1) {
                if(isAutoDown[0] == true && isAutoDown[N - 2] == true) {
                    E++;
                }
            }
            else {
                if(isAutoDown[i - 1] == true && isAutoDown[i + 1] == true) {
                    E++;
                }
            }
        }
    }
    cout<<total<<" "<<D<<" "<<E<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值