社区讨论

思想出问题了吗

P2035[USACO08JAN] iCow B参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mi6xwrn1
此快照首次捕获于
2025/11/20 12:37
4 个月前
此快照最后确认于
2025/11/20 12:37
4 个月前
查看原帖
CPP
#include <cstdio> 
#include <algorithm>
#include <iostream> 
#define SM 402600
#define INF 999999999

int n , t  ;

struct music {
    int number , wt ;
} a[SM] ;

inline int cmp ( music x , music y ) {
    return x . wt > y . wt ;
}

inline int comp ( int l , int r ) {
    int max = a[l].wt ; 
    int num = l ;
    for ( int i = l ; i <= r ; i ++ ) 
        if ( max < a[i].wt ) {
            max = a[i].wt ; 
            num = a[i].number ;
        }
    return num ;
}
// comp 表示从 x -> y ,最大权重的下标 
inline int Solvej ( ) {
    std :: sort ( a + 1 , a + n + 1 , cmp ) ;
/*	for ( int i = 1 ; i <= n ; i ++ ) {
        std :: cout << a[i].wt << "   " << a[i].number << '\n';
    }
    std :: cout << '\n' ; */
    int ans = a[1].wt;
    //std :: cout << "此时最大的权重" << ans << '\n' ; 
    if ( ans % ( n - 1 ) == 0 ) {
        int sum = ans / ( n - 1 ) ;
        for ( int i = 2 ; i <= n ; i ++ ) 
            a[i].wt += sum ;
        a[1].wt = 0 ;
        /*for ( int i = 1 ; i <= n ; i ++ ) {
            std :: cout << "1此时的作标:" << i << '\n'; 
            std :: cout << "1此时的权重:" << a[i].wt <<" " ;
            std :: cout << "1此时的数下标:" << a[i].number << '\n' ; 
        }*/
    } 
    else {
        int sumT = ans / ( n - 1 ) ;
        int kasT = ans - sumT * ( n - 1 ) ;
    //	std :: cout << "kasT:" << kasT <<'\n' ;
        for ( int i = 2 ; i <= n ; i ++ )
            a[i].wt += sumT ;
        int i = 2 ;
        while ( kasT >= 1 ) {
            a[i].wt += 1 ;
            i ++ ;
            kasT -- ;
        }
        a[1].wt = 0 ;

        /*for ( int i = 1 ; i <= n ; i ++ ) {
            std :: cout << "2此时的作标:" << i << '\n'; 
            std :: cout << "2此时的权重" << a[i].wt <<" " ;
            std :: cout << "2此时的数下标" << a[i].number << '\n' ; 
        }*/
    }
}


int main () {
    scanf ( "%d%d" , &n , &t ) ;
    for ( int i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[i].wt ) ;
        a[i].number = i ;
    }

    std :: printf ( "%d\n" , comp ( 1 , n ) ) ;
    //std :: cout << '\n' ;

    for ( int i = 1 ; i <= t ; i ++ ) {
        Solvej ( ) ;
        //std :: cout << '\n' ;std :: cout << '\n' ;std :: cout << '\n' ;std :: cout << '\n' ;
        std :: printf ( "%d\n" , comp ( 2 , n ) ) ;
    }
    return 0 ;
}
自己感觉思想没有问题
请大佬帮忙看看代码哪里有问题
自己也测试了很多,没找出来问题,上面那些注释,大家可以看看

献上我诚挚的祝福

%%%

回复

0 条回复,欢迎继续交流。

正在加载回复...