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

原题链接:CSP 201909-2 小明种苹果(续)

做题的水平,就是做什么都会错的水平

#include <bits/stdc++.h>
using namespace std;
#define ll long long

struct node
{
    ll num;
    ll drop;
    int flag;

}s[1010];

int f[1010]={0};

int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll sum=0,d=0,e=0;
    for(int i=0;i<n;i++)
    {
        int m;
        cin>>m;
        int s0;
        cin>>s0;
        s[i].num=s0;
        for(int j=1;j<=m-1;j++)
        {
            int tmp;
            cin>>tmp;
            if(tmp<=0)
            {
                s[i].drop+=tmp;
            }
            else if(tmp>0)
            {
                s[i].num+=s[i].drop;
                s[i].drop=0;
                if(s[i].num>tmp)
                {
                    s[i].flag=1;
                }
                s[i].num=tmp;
            }
        }
        if(s[i].flag==1)
        {
            d++;
            f[i]=1;
        }
        s[i].num+=s[i].drop;
        sum+=s[i].num;
    }
    for(int i=0;i<n;i++)
    {
        if(f[i]==1 && f[(i+1)%n]==1 && f[(i+2)%n]==1)
        {
            e++;
        }
    }
    cout<<sum<<" "<<d<<" "<<e<<endl;
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N=1010;

struct node
{
    int pre;
    int cut;
    int left;
    int drop;
}apple[N];
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n;
    int sum=0,droptree=0;
    for(int i=0;i<n;i++)
    {
        cin>>m>>apple[i].pre;
        int tmp;
        for(int j=0;j<m-1;j++)
        {
            cin>>tmp;
            if(tmp<=0) apple[i].cut+=abs(tmp);
            else
            {
                int pre=apple[i].pre-apple[i].cut;
                if(pre>tmp)
                {
                    apple[i].pre=tmp;
                    apple[i].cut=0;
                    apple[i].drop=1;
                }
            }
        }
        apple[i].left=apple[i].pre-apple[i].cut;
        sum+=apple[i].left;
        if(apple[i].drop) droptree++;
    }
    cout<<sum<<" "<<droptree<<" ";
    int drop3=0;
    for(int i=0;i<n;i++)
    {
        if(i==n-2)
        {
            if(apple[i].drop && apple[i+1].drop && apple[0].drop)  drop3++;
        }
        else if(i==n-1)
        {
            if(apple[i].drop && apple[0].drop && apple[1].drop)    drop3++;
        }
        else
        {
            if(apple[i].drop && apple[i+1].drop && apple[i+2].drop)  drop3++;
        }
    }
    cout<<drop3<<endl;
	return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值