问题描述
试题编号: | 201909-2 |
试题名称: | 小明种苹果(续) |
时间限制: | 1.0s |
内存限制: | 512.0MB |
问题描述: |
代码:简单模拟
后面统计可以改成if(ve[(i - 1 + n) % n] && ve[i] && ve[(i + 1) % n]) e++;
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int t=0,a=0,e=0;
vector<bool> ve;
cin>>n;
int m,d;
for(int i=0;i<n;i++){
bool luo=false;
cin>>m;
cin>>d;
int sum=d;
for(int j=1;j<m;j++){
cin>>d;
if(d<=0) sum+=d;
else{
if(sum>d) luo=true;
sum=d;
}
}
t+=sum;
if(luo) a++;
ve.push_back(luo);
}
cout<<t<<" "<<a<<" ";
for(int i=1;i<n-1;i++){
if(ve[i-1]&&ve[i]&&ve[i+1]) e++;
}
if(ve[n-1]&&ve[0]&&ve[1]) e++;
if(ve[n-2]&&ve[n-1]&&ve[0]) e++;
cout<<e;
return 0;
}
//4
//4 74 -7 -12 -5
//5 73 -8 -6 59 -4
//5 76 -5 -10 60 -2
//5 80 -6 -15 59 0