rq457 连续串之和

rq457 连续串之和

#include < iostream >
using   namespace  std;

int  n,s;
int  d,S;
int  c[ 10001 ];
int  main()
{
    scanf(
" %d%d " , & n, & s);
    S
= (n - 1 ) * n / 2 ;
    d
= S - s;
    
if (s > S || s <- S || d % 2 == 1 ){
        printf(
" NIE " );
        
return   0 ;
    }
    
for ( int  i = 2 ;i <= n; ++ i)
        c[i]
= 1 ;
    
int  k;
    
for ( int  i = 2 ;i <= n && d; ++ i){
        k
= (n - i + 1 ) * 2 ;
        
if (d >= k){
            c[i]
=- 1 ;
            d
-= k;
        }
    }
    k
= 0 ;
    printf(
" %d\n " ,k);
    
for ( int  i = 2 ;i <= n; ++ i){
        k
+= c[i];
        printf(
" %d\n " ,k);
    }
    
return   0 ;
}





你可能感兴趣的:(rq457 连续串之和)