/*
* CSP
* 201909-1 小明种苹果*/
#include <stdio.h>
#include <vector>
bool circle[1000] = {false};//判断连续三个true
using namespace std;
vector<vector<int> > tree;
vector<int> preeApple;//每棵树最后剩余的果子
int N;//N:苹果树棵树
int sumApples = 0;
int subTree = 0;//发生掉苹果的树的棵树
int circleNum = 0;
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
vector<int> temp;
int M = 0;
scanf("%d", &M);
for (int j = 0; j < M; j++) {
int tempNum;
scanf("%d", &tempNum);
temp.push_back(tempNum);
}
tree.push_back(temp);
}
for (int i = 0; i < tree.size(); i++) {
int tempSumApples = tree[i][0];
for (int j = 0; j < tree[i].size(); j++) {
if (j > 0) {
//判断是否有负数
if (tree[i][j] <= 0) {
tempSumApples += tree[i][j];
} else if (tree[i][j] < tempSumApples) {
//判断是不是真的掉落果子
tempSumApples = tree[i][j];
circle[i] = true;
}
}
}
sumApples += tempSumApples;
if (circle[i])
subTree++;
}
int n = N;
if (n >= 3)
for (int i = 0; i < n; i++)
if (circle[(i - 1 + n) % n] && circle[i] && circle[(i + 1) % n])
{
circleNum++;
}
printf("%d %d %d\n", sumApples, subTree, circleNum);
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
5
4 10 0 9 0
4 10 -2 7 0
2 10 0
4 10 -3 5 0
4 10 -1 8 0
*/
CCF201909-2 小明种苹果(续)
最新推荐文章于 2022-04-26 09:15:40 发布