题目分析:
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
#define REP( i , a , b ) for ( int i = ( a ) ; i < ( b ) ; ++ i )
#define FOR( i , a , b ) for ( int i = ( a ) ; i <= ( b ) ; ++ i )
#define REV( i , a , b ) for ( int i = ( a ) ; i >= ( b ) ; -- i )
#define travel( e , H , u ) for ( Edge* e = H[u] ; e ; e = e -> next )
#define CLR( a , x ) memset ( a , x , sizeof a )
typedef long long LL ;
const int MAXN = 100005 ;
int n ;
LL a[MAXN] ;
bool check ( int l , int r ) {
bool flag1 = 1 , flag2 = 1 ;
FOR ( i , l + 1 , r ) {
if ( a[i - 1] > a[i] ) flag1 = 0 ;
if ( a[i - 1] < a[i] ) flag2 = 0 ;
}
return flag1 || flag2 ;
}
void scanf ( LL& x , char c = 0 , bool flag = 0 ) {
while ( ( c = getchar () ) != '-' && ( c < '0' || c > '9' ) ) ;
if ( c == '-' ) flag = 1 , x = 0 ;
else x = c - '0' ;
while ( ( c = getchar () ) >= '0' && c <= '9' ) x = x * 10 + c - '0' ;
if ( flag ) x = -x ;
}
void solve () {
scanf ( "%d" , &n ) ;
int l = 0 , r = n - 1 ;
REP ( i , 0 , n ) scanf ( a[i] ) ;
REP ( i , 0 , n ) {
while ( l < r && !a[l] ) ++ l ;
while ( l < r && !a[r] ) -- r ;
if ( l > 0 ) -- l ;
if ( r < n - i - 1 ) ++ r ;
if ( !check ( l , r ) ) {
if ( i ) printf ( "%d\n" , i - 1 ) ;
else printf ( "ugly series\n" ) ;
return ;
} else if ( r - l <= 2 ) {
printf ( "nice series\n" ) ;
return ;
}
REP ( j , l , r ) a[j] = a[j + 1] - a[j] ;
-- r ;
}
}
int main () {
int T ;
scanf ( "%d" , &T ) ;
while ( T -- ) solve () ;
return 0 ;
}