喜迎暑假多校联赛第二场

A 蕾凹娜的哀伤

完全背包的模板题,但是卡了一下时间要用二进制枚举优化一下

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

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

const int N = 3005 , M = 20005;
int f[M] ;
vector< pair<int,int> > ve;


int32_t main() {
    int  n = read() , m = read();
    for( int i = 1 , ti , wi , si , p ; i <= n ; i ++ ){
        ti = read() , wi = read() , si = read() , p = 1;
        while( si > p ) si -= p , ve.push_back({ ti * p , wi * p } ) , p <<=1 ;
        if( si > 0 ) ve.push_back( {ti * si , wi * si } );
    }
    for( auto [ v , w ] : ve ){
        for( int i = m ; i >= v ; i -- )
            f[i] = max( f[i] , f[i-v] + w );
    }
    cout << f[m] << "\n";
}

B 清楚姐姐打CF

签到题

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

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}


int32_t main() {
    int n = read() , k = read() , tp = 0;
    for( int x  ; n ; n -- )
        x = read() , tp = max( tp , x );
    if( k > tp ) cout << "0\n";
    else cout << tp - k << "\n";
    return 0;
}

D N个数的和

卡读入,要用快读,并且不能处理负数

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

int read() {
    int x = 0, ch = getchar();
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x;
}

int32_t main() {
    int res = 0;
    for( int n = read() ; n ; n -- )
        res += read();
    cout << res <<"\n";
}

E 最佳直播时间

将时间转化为到00:00:00有多少秒,然后用差分维护一下区间修改即可

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

int read() {
    int x = 0, ch = getchar();
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x ;
}
const int N = 5e6+5;
int f[N];

int32_t main() {
    int n = read() , res = 0 , m = 0;
    for( int h1 , m1 , s1 , h2 , m2 , s2 ,t1 , t2 ; n ; n -- )
    {

        h1 = read() , m1 = read() , s1 = read() , h2 = read() , m2 = read() , s2 = read();
        t1 = s1 + m1 * 60 + h1 * 3600 , t2 = s2 + m2 * 60 + h2 * 3600;
        f[t1] ++ , f[t2+1] -- , m = max( m , t2 );
    }

    res = f[0];
    for( int i = 1 ; i <= m ; i ++ )
        f[i] += f[i-1] ,  res = max( res , f[i] );
    cout << res << "\n";
}

F 鼠标的天选

签到题,暴力的遍历就好了

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

int read() {
    int x = 0, f = 1, ch = getchar();
    while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
    if (ch == '-') f = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
    return x * f;
}

int32_t main() {
    int n = read() , res= 0;
    for( ; n ; n -- ){
        string s;
        cin >> s;
        for( int i = 0 ; i + 5 <= s.size() ; i ++ )
            if( s.substr( i ,5 ) == "month" ){
                res ++;
                break;
            }
    }
    cout << res << "\n";
}

H 关注牛客竞赛喵,关注牛客竞赛谢谢喵

签到

https://space.bilibili.com/414380929
posted @ 2022-08-01 09:46  PHarr  阅读(18)  评论(0编辑  收藏  举报