首页 > 其他分享 >Codeforces Round 867 (Div. 3)(A-C)

Codeforces Round 867 (Div. 3)(A-C)

时间:2023-04-25 16:13:13浏览次数:31  
标签:1000000001 ll max1 Codeforces long max2 solve 867 Div

A. TubeTube Feed

签到题


思路

往后走,每次减一,记录当前所能得到最大的bi

完整代码

#include<bits/stdc++.h>
using namespace std ;
#define ll long long
inline ll read(){
    ll s=0 ; char g=getchar() ; while( g>'9'||g<'0')g=getchar() ; 
    while( g>='0'&&g<='9')s=s*10+g-'0',g=getchar() ; return s ; 
}
ll a[51] , b[51] ; 
void solve(){
    ll n = read() , k = read() ; 
    for( int i = 1 ; i <= n ; ++i )a[i] = read() ; 
    for( int i = 1 ; i <= n ; ++i )b[i] = read() ;
    ll ans = -1 , mans = 0 ; 
    for( int i = 1 ; i <= n ; ++i ){
        if( k >= a[i] && b[i] > mans )mans = b[i] , ans = i ;
        k-- ; 
    }
    cout<<ans<<endl ; 
}
int main(){
    ll q = read() ; 
    while( q-- ){
        solve() ; 
    }
    return 0 ; 
}

B. Karina and Array

ssw:笑死,搞忘初值不能为0了


思路

通常来说,记录数列中的最大值和次大值,相乘即答案
但存在负值,所以还要记录最小值和次小值
二者取max

注意下初始值的问题,不要赋值为0

完整代码

#include<bits/stdc++.h>
using namespace std ;
#define ll long long
void solve(){
    ll n  ; cin>> n ; 
    ll max1 = -1000000001 , max2 = -1000000001 , min1 = 1000000001 , min2 = 1000000001 ;
    for( int i = 1 ; i <= n ; ++i ){
        ll x ; cin>>x ; 
        if( x >= max1 ){
            max2 = max1 ; max1 = x ;
        }
        else if( x >= max2 )max2 = x ;
        if( x <= min1 ){
            min2 = min1 ; min1 = x ;
        }
        else if( x <= min2 )min2 = x ; 
    } 
    cout<<max( max1*max2 , min1*min2 )<<endl ; 

}
int main(){
    ll q ; cin>>q ; 
    while( q-- ){
        solve() ; 
    }
    return 0 ; 
}

C. Bun Lover

XXX:这不都是一眼题吗?


思路

主要思路

找规律嘛, f[n+1] = f[n]+2*n+1
然后拆开递推式即可f[n]=2+2n+n^2

代码

void solve(){
    ll n  ; cin>> n ; 
    cout<<2ll+2ll*n+n*n<<endl ;
}

D. Super-Permutation

fxs:看6就行
橘子熊:我猜的,但对了


思路

主要思路

首先明确我们是要利用前缀和取模后再凑出一组 0 到 n-1
然后看看样例取模,就能找到规律 0 5 1 4 2 3
反向推出数列即可

代码

void  solve(){
    int n ; cin>>n ;
    if( n == 1 )cout<<1<<endl ; 
    else if ( n%2 )cout<<-1<<endl ; 
    else {
        for( int i = 0 ; i < n ; ++i){
            if( i%2 )cout<<n-i<<" " ; 
            else if( i==0 )cout<<n<<" " ;  
            else cout<<i<<" " ; 
        }
        cout<<endl ;
    }
}

标签:1000000001,ll,max1,Codeforces,long,max2,solve,867,Div
From: https://www.cnblogs.com/ssw02/p/17352918.html

相关文章

  • CF1479 Div1 VP记录
    战况:别的不说,这个B1WA3发是真的精髓。A略B我们设此时在第一队队尾的为las0,在第二队队尾的为las1,要放的数为x。先考虑B1:显然有:如果las0等于x,放在第二队,如果las1等于x,放在第一队。考虑两边都不同的情况,我们想要这个x后面尽快跟上一个不同的数,依此来创造新的......
  • Codeforces Round #459 (Div. 2) D. MADMAX DAG&&博弈
    Asweallknow,Maxisthebestvideogameplayeramongherfriends.Herfriendsweresojealousofhers,thattheycreatedanactualgamejusttoprovethatshe’snotthebestatgames.Thegameisplayedonadirectedacyclicgraph(aDAG)withnvertic......
  • 2014 Pacific Northwest Region Programming Contest—Division 2 Problem U — lim
    Incollegefootball,manydifferentsourcescreatealistoftheTop25teamsinthecountry.Sinceit’ssubjective,theselistsoftendiffer,butthey’reusuallyverysimilar.Yourjobistocomparetwooftheselists,anddeterminewheretheyaresimi......
  • Codeforces Round #306 (Div. 2) D. Regular Bridge 构造
    Anundirectedgraphiscalledk-regular,ifthedegreesofallitsverticesareequalk.Anedgeofaconnectedgraphiscalledabridge,ifafterremovingitthegraphisbeingsplitintotwoconnectedcomponents.Buildaconnectedundirectedk-regularg......
  • Codeforces Round #465 (Div. 2) D. Fafa and Ancient Alphabet 数学概率
    AncientEgyptiansareknowntohaveusedalargesetofsymbolstowriteonthewallsofthetemples.FafaandFifawenttooneofthetemplesandfoundtwonon-emptywordsS1andS2ofequallengthsonthewalloftemplewrittenonebelowtheother.Sinc......
  • Educational Codeforces Round 48 (Rated for Div. 2) D. Vasya And The Matrix
    NowVasyaistakinganexaminmathematics.Inordertogetagoodmark,Vasyaneedstoguessthematrixthattheteacherhasconstructed!Vasyaknowsthatthematrixconsistsofnrowsandmcolumns.Foreachrow,heknowsthexor(bitwiseexcludingor)......
  • Codeforces 1804G - Flow Control(势能分析)
    成功把这道小清新题做成了一道大数据结构题,我的评价是我是小丑。首先显然要离散化对时间轴扫描线。这个除以\(2\)下取整的操作显然启示我们往势能的方向思考,也就是我们希望能够找到某个变量,使得这个变量的均摊变化次数在可接受范围内。但是直接以每个元素的值为势能好像也不太......
  • Educational Codeforces Round 47 (Rated for Div. 2) C. Annoying Present 数
    Alicegotanarrayoflengthnasabirthdaypresentonceagain!Thisisthethirdyearinarow!Andwhatismoredisappointing,itisoverwhelmenglyboring,filledentirelywithzeros.BobdecidedtoapplysomechangestothearraytocheerupAlice.......
  • Codeforces Round #156 (Div. 2) C. Almost Arithmetical Progression dp
    Genalovessequencesofnumbers.Recently,hehasdiscoveredanewtypeofsequenceswhichhecalledanalmostarithmeticalprogression.Asequenceisanalmostarithmeticalprogression,ifitselementscanberepresentedas:a1 = p,wherepissomeintege......
  • Codeforces Round #285 (Div. 2) B. Misha and Changing Handles map 映射
    MishahackedtheCodeforcessite.Thenhedecidedtoletalltheuserschangetheirhandles.Ausercannowchangehishandleanynumberoftimes.Buteachnewhandlemustnotbeequaltoanyhandlethatisalreadyusedorthatwasusedatsomepoint.Mish......