csp 201909-2 小明种苹果(续)

cpp 复制代码
#include<iostream>
using namespace std;

int main(){
    int n,m;
    cin>>n;
    int apple[n];
    int drop[n];
    for(int i=0;i<n;i++){
        cin>>m>>apple[i];
        drop[i]=0;
        for (int j = 0; j < m-1; ++j) {
            int temp;
            cin>>temp;
            if(temp<=0) apple[i]+=temp;
            else {
                if(temp!=apple[i])  {
                    drop[i]=1;
                    apple[i]=temp;
                }
            }
        }
    }

    int sum=0,Applesum=0,dropsum=0;
    for(int i=0;i<n;i++){
        Applesum+=apple[i];
        if(drop[i]==1) dropsum++;
        int pre=i,mid=(i+1)%n,succ=(i+2)%n;
        if(drop[pre]==1&&drop[mid]==1&&drop[succ]==1) {
            sum++;
        }
    }

    cout<<Applesum<<" "<<dropsum<<" "<<sum;
    return 0;
}
相关推荐
米粒111 分钟前
力扣算法刷题 Day 31 (贪心总结)
算法·leetcode·职场和发展
少许极端15 分钟前
算法奇妙屋(四十)-贪心算法学习之路7
java·学习·算法·贪心算法
AlenTech41 分钟前
647. 回文子串 - 力扣(LeetCode)
算法·leetcode·职场和发展
py有趣1 小时前
力扣热门100题之合并两个有序链表
算法·leetcode·链表
8Qi81 小时前
LeetCode热题100--45.跳跃游戏 II
java·算法·leetcode·贪心算法·编程
foundbug9991 小时前
基于STM32的步进电机加减速程序设计(梯形加减速算法)
stm32·单片机·算法
东北甜妹2 小时前
MYSQL 总结
数据结构
CheerWWW2 小时前
C++学习笔记——this关键字、对象生命周期(栈作用域)、智能指针、复制与拷贝构造函数
c++·笔记·学习
lucky九年2 小时前
GO语言模拟C++封装,继承,多态
开发语言·c++·golang
北顾笙9802 小时前
day12-数据结构力扣
数据结构·算法·leetcode