首页 > 其他分享 >牛客小白月赛 54

牛客小白月赛 54

时间:2022-11-10 10:55:58浏览次数:36  
标签:ch int 54 long 牛客 while && 小白月赛 getchar

A sum

把所有的数放进一个大根堆,然后每次取出最大的两个相加,累加到答案中去,并重新放回到大根堆。

最大两数之和重新放入大根堆依旧是最大的数,所以可以优化成前缀和来做。

#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 = 2e5+12 , mod = 1e7 + 7;
int a[N];

void solve(){
    int n = read() , res = 0;
    for( int i = 1 ; i <= n ; i ++ ) a[i] = read();
    sort( a + 1 , a + 1 + n , greater<int>() );
    int sum = a[1];
    for( int i = 2 ; i <= n ; i ++ ) {
        sum += a[i] ;
        if( sum < 0 ) break;
        res += sum;
        res %= mod;
    }
    cout << res << "\n";
    return;
}

int32_t main() {
    for( int T = read() ; T ; T -- )
        solve();
    return 0;
}

B Gaming

因为要下选择和一个 debuff 不选,所以要找到哪一个debuff 的积分最少,然后把这个 debuf 的积分删掉

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

const int N = 1e6+5;
int n , m , a[N] , res = LONG_MAX , sum;

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() {
    n = read() , m = read();
    for( int l , r , w ; n ; n -- )
        l = read() , r = read() , w = read() , a[l] += w , a[r+1] -= w , sum += w;
    for( int i = 1 ; i <= m ; i ++ ) a[i] += a[i-1] , res = min( res , a[i] );
    cout << sum - res << "\n";
    return 0;
}

C School

首先时间可以全部转化成距离

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

int n , h , m , q;

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;
}

int get( int x , int y ){
    return x * m + y;
}
vector<pair<int,int>> p , t;

pair<int,int> Find( int x ){
    int l = 0 , r = t.size() - 1 , mid , res;
    while( l <= r ) {
        mid = (l + r) >> 1;
        if (t[mid].first <= x) res = mid, l = mid + 1;
        else r = mid - 1;
    }
    return  t[res];
}

int32_t main() {
    n = read() , h = read() , m = read() , q = read();
    for( int a , b , c , d ; n ; n -- ){
        a = read() , b = read() , c = read() , d = read();
        p.push_back( { get(a,b) , get(c,d) } );
    }

    sort( p.begin() , p.end() , []( pair<int,int> a , pair<int,int> b ){ return a.first < b.first;}  );
    t.push_back( {0,0} );
    for( auto [ l , r ] : p ){
        if( l <= t.back().second ) t.back().second = max( t.back().second , r );
        else t.push_back( { l , r } );
    }
    for( int x , a , b ; q ; q -- ){

        a = read() , b = read() , x  = get( a , b );
        auto k = Find(x);
        if( k.second >= x ) cout << "No\n";
        else cout << "Yes\n";
    }
    return 0;
}

D Word

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


int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n , m; cin >> n >> m;
    vector< string > g(n+2);

    for( int i = 1 ; i <= n ; i ++ )
        cin >> g[i];
    cin >> g[0] >> g[n+1];
    vector e( n+2 , vector<int>() );
    for( int i = 0 ; i <= n+1 ; i ++ )
        for( int j = 0 ; j < i ; j ++ ){
            int cnt = 0;
            for( int l = 0 ; l < m && cnt < 2 ; l ++ )
                if( g[i][l] != g[j][l] ) cnt ++;
            if( cnt < 2 ) e[i].push_back(j) , e[j].push_back(i);
        }
    vector<int> dis( n+2 , INT_MAX );
    dis[0] = 0;
    vector lst( n + 2 , vector<int>() );
    lst[0].push_back(0);
    queue< int > q;
    q.push(0);
    while( q.size() ) {
        int u = q.front(); q.pop();
        if( u == n + 1 ){
            cout << dis[u]-1 << "\n";
            for( auto i : lst[u] )
                cout << g[i] << "\n";

            return 0;
        }
        for( auto v : e[u] ){
            if( dis[v] > dis[u]+1 ) dis[v] = dis[u]+1 , q.push(v) , lst[v] = lst[u] , lst[v].push_back(v);
        }
    }
    cout << "-1";
    return 0;
}

标签:ch,int,54,long,牛客,while,&&,小白月赛,getchar
From: https://www.cnblogs.com/PHarr/p/16876349.html

相关文章

  • 牛客小白月赛55
    A至至子的等差中项#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){inta,b;cin>>a>>b;cout<<b*2-a<<"\n";}B至至......
  • HDU 5446 Unknown Treasure
    ProblemDescriptionOnthewaytothenextsecrettreasurehidingplace,themathematiciandiscoveredacaveunknowntothemap.Themathematicianenter......
  • HDU 5434 Peace small elephant
    ProblemDescriptionXiaoMinglikesplayingtheinternationalchess,especiallyliketheelephant(itcanmovebyslantwhilenobarrier),buthethink......
  • HDU 5442 Favorite Donut
    ProblemDescriptionLuluhasasweettooth.Herfavoritefoodisringdonut.Everydayshebuysaringdonutfromthesamebakery.Aringdonutisconsis......
  • 广告行业中那些趣事系列54:从理论到实践学习当前超火的多模态学习模型
    导读:本文是“数据拾光者”专栏的第五十四篇文章,这个系列将介绍在广告行业中自然语言处理和推荐系统实践。本篇从理论到实践介绍了当前超火的多模态学习模型,想了解多模态学习......
  • 454. 四数相加 II
    454.四数相加II给你四个整数数组nums1、nums2、nums3和nums4,数组长度都是n,请你计算有多少个元组(i,j,k,l)能满足:0<=i,j,k,l<nnums1[i]+nums2......
  • 牛客练习赛105
    切蛋糕的贝贝题意:将多边形一个蛋糕切成6份,使得面积之比为1:1:4:5:1:4(顺序可以打乱),只有两种切法,一种是将过外接圆的多边形的对角线,第二种是从多边形的中心和顶点的连线,先......
  • HDU 5432 Pyramid Split
    ProblemDescriptionXiaoMingisacitizenwho'sgoodatplaying,hehaslot'sofgoldconeswhichhavesquareundersides,let'scallthempyramids.Anyo......
  • HDU 5496 Beauty of Sequence
    ProblemDescriptionSequenceisbeautifulandthebeautyofanintegersequenceisdefinedasfollows:removesallbutthefirstelementfromeveryconse......
  • HDU 5433 Xiao Ming climbing
    ProblemDescriptionDuetothecursemadebythedevil,XiaoMingisstrandedonamountainandcanhardlyescape.Thismountainisprettystrangethat......