Files
python/TangDou/XiTi/1344.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

83 lines
1.8 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> vb;
for (int i = 0; i < N; i++) {
int m;
cin >> m;
vector<int> v1;
for (int j = 0; j < m; j++) {
int c;
cin >> c;
v1.push_back(c);
}
vb.push_back(v1);
}
//1、从后向前找找第一个大于0的数字然后再从它开始向后一直到头加在一起
//2、计算D
int T = 0, D = 0, E = 0;
vector<int> vShuGuo;
int j;
for (int i = 0; i < N; i++) {
int pos;
for (j = vb[i].size() - 1; j >= 0; j--) {
if (vb[i][j] > 0) {
pos = j;
break;
}
}
//计算T
for (int k = pos; k < vb[i].size(); k++) {
T += vb[i][k];
}
//计算D
int sum = 0;
for (int k = 0; k < pos; k++) {
sum += vb[i][k];
}
if (sum > vb[i][pos]) {
D++;
vShuGuo.push_back(i + 1);
}
}
//计算E的值
unordered_map<int, int> _map;
for (int i = 0; i < vShuGuo.size(); i++) {
_map[vShuGuo[i]]++;
}
for (int i = 0; i < vShuGuo.size(); i++) {
int next, nextnext;
if (vShuGuo[i] == N) next = 1;
else next = vShuGuo[i] + 1;
if (next == N) nextnext = 1;
else nextnext = next + 1;
if (_map.count(next) > 0 && _map.count(nextnext) > 0) {
E++;
}
}
cout << T << " " << D << " " << E << endl;
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
*/