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;
}
相关推荐
不会就选b4 小时前
算法日常・每日刷题--<贪心>25
数据结构·算法
蒸蒸yyyyzwd4 小时前
秋招学习笔记 day46
c++·八股
Cccp.1237 小时前
【leetcode】(七)前缀树和贪心算法
数据结构·leetcode·贪心算法
千里码aicood7 小时前
基于CART算法的图书分类系统设计与实现
数据库·算法·分类
码匠许师傅7 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务
开发语言·c++·http
做cv的小昊8 小时前
【World Model】π0.5:a Vision-Language-Action Model with Open-World Generalization
人工智能·算法·机器学习·大模型·多模态·vla·世界模型
لا معنى له8 小时前
World-In-World: World Models in a Closed-Loop World
算法
无名猿8 小时前
new/delete 与 malloc/free:为什么绝对不能混用
c++·内存管理·现代c++·踩坑记录
Logic10110 小时前
C语言/数据结构位运算题解:异或XOR找出多任务下载器中的“独特下载速度“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质