AcWing杯 第 84 场周赛

A. 最大数量

签到,用了结构化绑定

#include<bits/stdc++.h>
#define int long long
using namespace std;

int read(){...}

int32_t main(){
    int n = read();
    map<pair<int,int>,int> cnt;
    pair<int,int> time;
    auto &[ h , m ] = time;
    for( ; n ; n -- )
        h = read() , m = read() , cnt[time]++;
    int res = 0;
    for( auto [k,v] : cnt )
        res = max( res , v );
    cout << res << "\n" ;
    return 0;
}

B.前缀和序列

题目名是解法?

#include<bits/stdc++.h>
#define int long long
using namespace std;

int read() {...}

int32_t main(){
    int n = read();
    vector<int> a(n+1);
    for( int i = 1 ; i <= n ; i ++ ) a[i] = read();
    auto b = a;
    sort( b.begin()+1 , b.end() );
    for( int i = 1 ; i <= n ; i ++ ) a[i] += a[i-1] , b[i] += b[i-1];
    for( int op , l , r , m = read() ; m ; m -- ){
        op = read() , l = read() , r = read();
        if( op == 1 ) cout << a[r] - a[l-1] << "\n";
        else cout << b[r] - b[l-1] << "\n";
    }
    return 0;
}

C. 买可乐

数据范围不大,枚举一下买多少瓶,然后计算一下买多少箱,最后计算一下花费,取最小值即可。

#include<bits/stdc++.h>
using namespace std;

int main(){
    int c , d , n , m , k;
    cin >> c >> d >> n >> m >> k;
    if( k >= n*m ) {
        cout << 0;
        return 0;
    }
    int res = INT_MAX , t = n * m - k;
    for( int i = 0 , j ; i <= t ; i ++ ){
        j = t - i , j = (j/n) + (j%n>0);
        res = min( res , i*d + j*c );
    }
    cout << res;
    return 0;
}
posted @ 2023-01-08 15:13  PHarr  阅读(10)  评论(0编辑  收藏  举报