abc_474

2026.2.7 ABC_474 赛时&补题记录

\(\textup{Link.}\)

打的还可以,因为是周日才打的,苏醒之后就开始蒙蒙地打。


A - Not X

直接做。

$\textup{Code.}$
#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e5 + 5;
int x;
void slove(){
    cin >> x;
    cout << ( x == 3 ? 1 : 3 );
}

signed main(){
    // freopen( ".in", "r", stdin );
    // freopen( ".out", "w", stdout );
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );
    int T = 1;
    // cin >> T;
    while( T -- )
        slove();
    return 0;
}

B - Exit Order

题意不知道叽里咕噜在说啥,又是文字游戏。

$\textup{Code.}$
#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 105;
int N;
int p[MAXN];
void slove(){
    cin >> N;
    for( int i = 1; i <= N; i ++ ){
        cin >> p[i];
    }
    int now = 0;
    for( int i = 1; i <= N; i ++ ){
        if( ( p[i] - 1 ) / 10 != ( i - 1 ) / 10 ){
            cout << "No";
            return;
        }
        // cout << p[i] / 10 << " " << i / 10 + 1 << endl;
    }
    cout << "Yes";
}

signed main(){
    // freopen( ".in", "r", stdin );
    // freopen( ".out", "w", stdout );
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );
    int T = 1;
    // cin >> T;
    while( T -- )
        slove();
    return 0;
}

C - Remove and Append

记录一下每个数的位置就行了,最多也就两倍的长度,删除就直接赋为极大值就行了。

$\textup{Code.}$
#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 4e5 + 5;
int N, Q;
int p[MAXN], pos[MAXN];
void slove(){
    cin >> N >> Q;
    for( int i = 1; i <= N; i ++ ){
        cin >> p[i];
        pos[p[i]] = i;
    }
    while( Q -- ){
        int a;
        cin >> a;
        int k = p[pos[a]];
        p[pos[a]] = inf;
        p[++ N] = k;
        pos[a] = N;
    }
    for( int i = 1; i <= N; i ++ ){
        if( p[i] == inf ) continue;
        cout << p[i] << " ";
    }
}

signed main(){
    // freopen( ".in", "r", stdin );
    // freopen( ".out", "w", stdout );
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );
    int T = 1;
    // cin >> T;
    while( T -- )
        slove();
    return 0;
}

D - Outweigh

考虑贪心。

直觉告诉我们,如果一个石头足够大,足够多,那么应该可以贪心出来。

于是我们找到比多面多最多个的石头,如果都没多的话那么就一定无解就行了。

那么除了这个石头之外都变成 1,全部给这个石头,最后判一下无解就行啦。

$\textup{Code.}$
#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e5 + 5;
int N;
int fnd = -1, sum;
int a[MAXN], b[MAXN], c[MAXN];
void slove(){
    cin >> N;
    for( int i = 1; i <= N; i ++ ){
        cin >> a[i];
    }
    bool flag = true;
    for( int i = 1; i <= N; i ++ ){
        cin >> b[i];
        c[i] = a[i] - b[i];
        if( c[i] > 0 ) flag = false;
        if( fnd == -1 || c[i] > c[fnd] ) fnd = i;//找到最大数
    }
    if( flag ){
        cout << "No";
        return;
    } else cout << "Yes\n";

    for( int i = 1; i <= N; i ++ )
        if( i != fnd ) sum += c[i];
    for( int i = 1; i <= N; i ++ ){
        if( i == fnd ){
            if( sum >= 0 ) cout << 1 << " ";
            else cout << 1 - sum / c[fnd] << " ";//贪心
        } else cout << 1 << " ";
    }
}

signed main(){
    // freopen( ".in", "r", stdin );
    // freopen( ".out", "w", stdout );
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );
    int T = 1;
    // cin >> T;
    while( T -- )
        slove();
    return 0;
}

E - One Time Coupon

继续考虑一个贪心。

假设全部都用优惠券买的话

晚点再写。

$\textup{Code.}$
#include<bits/stdc++.h>
#define int long long
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2e5 + 5;
int N;
struct node{
    int a, b;
}a[MAXN];

bool cmp( node a, node b ){
    return ( a.a - a.b ) < ( b.a - b.b );
}

void slove(){
    int sum = 0, minn = inf, psum = 0, ans = inf;
    cin >> N;
    for( int i = 1; i <= N; i ++ ){
        cin >> a[i].a >> a[i].b;
        sum += a[i].b, minn = min( a[i].a, minn );
    }
    sort( a + 1, a + N + 1, cmp );
    for( int i = 0; i <= N; i ++ ){
        ans = min( ans, sum + psum + max( 0LL, N - 2 * i ) * minn );
        psum += ( a[i + 1].a - a[i + 1].b );
    }
    cout << ans << "\n";
}

signed main(){
    // freopen( ".in", "r", stdin );
    // freopen( ".out", "w", stdout );
    ios::sync_with_stdio( false );
    cin.tie( 0 );
    cout.tie( 0 );
    int T = 1;
    cin >> T;
    while( T -- )
        slove();
    return 0;
}
$\textup{Code.}$

posted @ 2026-09-06 20:02  Fαll  阅读(47)  评论(4)    收藏  举报