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;
}
相关推荐
Irissgwe2 分钟前
顺序表和链表
数据结构·c++·链表·c·顺序表·线性表
TCW11212 分钟前
AI底层系列:用C++实现线性代数的公式推导与算法设计-基础篇-5.矩阵方程
人工智能·线性代数·算法
叫我:松哥4 分钟前
基于机器学习和flask的体育健身风险智能分析系统,系统集成DeepSeek、聚类算法、分类算法等,准确率达90%
人工智能·python·神经网络·算法·机器学习·flask·聚类
wabs6667 分钟前
关于动态规划【0-1背包思想在实际问题中是怎么转化的?】
算法·动态规划
阿文的代码库9 分钟前
欧拉回路与欧拉路径的算法流程演示
算法
牛油果子哥q13 分钟前
二叉树(Binary Tree)零基础精讲,树基础概念、树形分类、核心性质、递归/层序遍历、完整代码与面试考点全解
c++·面试·数据挖掘
汤姆yu15 分钟前
云知声 U2 原生智能体大模型深度解析
大数据·人工智能·算法·ai·大模型·多模态·智能体
小糯米60117 分钟前
C语言文件操作
c语言·开发语言·数据结构
syt_biancheng21 分钟前
贪心算法(1)---简介
算法·贪心算法
一切皆是因缘际会28 分钟前
神经符号融合智能体
大数据·数据结构·人工智能·ai