You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 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
*/