社区讨论

请大佬 指教 ,此code 如何去重?

P2879[USACO07JAN] Tallest Cow S参与者 2已保存回复 2

讨论操作

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

当前回复
2 条
当前快照
1 份
快照标识符
@mi7we5q7
此快照首次捕获于
2025/11/21 04:42
4 个月前
此快照最后确认于
2025/11/21 04:42
4 个月前
查看原帖
CPP
#include <cstdio>
#include <iostream>
#include <algorithm>

#define P signed
#define SM 402600

using namespace std ;
P N , I , H , R ;
P a[SM] ;
P first = 1 ;
//  Line 1: Four space-separated integers: N, I, H and R

struct Code {
    int left , right ;
}x[SM] ;

P comp ( Code l , Code r ) {
    return l.left < r.left ;
}

P main ( ) {
    scanf ( "%d%d%d%d" , &N , &I , &H , &R ) ;
    for ( int i = 1 ; i <= N ; i ++ ) a[i] = H ;
    for ( int i = 1 ; i <= R ; i ++ ) scanf ( "%d%d" , &x[i].left , &x[i].right ) ;
    sort ( x + 1 , x + R + 1 , comp ) ;
    for ( int i = 1 ; i <= R ; i ++ )
        if ( x[i].left <= x[i].right ) 
            for ( int it = x[i].left + 1 ; it < x[i].right ; it ++ ) a[it] -= 1 ;
        else for ( int is = x[i].left - 1 ; is > x[i].right ; is -- ) a[is] -= 1 ;
    for ( int i = 1 ; i <= N ; i ++ ) {
        if ( first ) printf ( "%d" , a[i] ) , first = 0 ;
        else printf ( "\n%d" , a[i] ) ;
    }
    fclose (stdin) , fclose (stdout) ;
    return 0 ;
}

回复

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

正在加载回复...