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;
}
相关推荐
程序员老陆1 分钟前
C++ 悬空指针:从原理到工程级解决方案
开发语言·c++·程序设计
漂流瓶jz15 分钟前
UVA-1610 聚会游戏 题解答案代码 算法竞赛入门经典第二版
数据结构·c++·算法·题解·aoapc·算法竞赛入门经典·uva
随意起个昵称23 分钟前
【线性DP】P10156 [LSOT-2] 胜者组
c++·动态规划
imDwAaY23 分钟前
Redis Set 如何节省内存?从整数集合到哈希表的设计取舍
数据结构·redis·散列表
yyy(十一月限定版)27 分钟前
CF2131D Arboris Contractio
算法
无名猿29 分钟前
map / set 完全指南:红黑树与有序容器
数据结构·c++·性能优化·stl·标准库
朝朝辞暮i36 分钟前
C++ 第 28 课:Lambda 表达式
开发语言·c++·算法
代码什么用39 分钟前
LeetCode-560.和为 K 的子数组
算法·leetcode
All for pursuit.43 分钟前
【回溯-3】39.组合总和
数据结构·c++·算法·leetcode
释厄6231 小时前
BSD 基础论——不要忘记连接·不要停滞循环·AI基础算法
人工智能·算法