首页 > 其他分享 >Codeforces Round 964 (Div. 4)

Codeforces Round 964 (Div. 4)

时间:2024-08-08 14:18:13浏览次数:14  
标签:964 int Codeforces pos ++ cnt2 ans Div include

Codeforces Round 964 (Div. 4)

A送分

B

大意:两个人两张牌 随机翻 求a翻出来的牌比b大的可能

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#define ep emplace_back 
using namespace std;

void solve() {
    int ans = 0;
    int a1, b1, a2, b2;
    cin >> a1 >> a2 >> b1 >> b2;
    
    int cnt1 = 0, cnt2 = 0;
    if (a1 > b1)
        cnt1++;
    else if (a1 < b1)
        cnt2++;

    if (a2 > b2)
        cnt1++;
    else if (a2 < b2)
        cnt2++;

    if (cnt1 > cnt2) 
        ans += 2;

    cnt1 = cnt2 = 0;
    if (a1 > b2)
        cnt1++;
    else if (a1 < b2)
        cnt2++;

    if (a2 > b1)
        cnt1++;
    else if (a2 < b1)
        cnt2++;

    if (cnt1 > cnt2) 
        ans += 2;

    cout << ans << "\n";
}

int main() {
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

C

题目大意:有些区间被阻断 找连续的区间 判断最长的长度能否大于S

思路:保证l,r是不相交的 扫一遍所有的区间就好了 跑两个指针 pos1=0,pos2=l

#include<iostream>
using namespace std;
void solve(){
    int n,s,m;
    scanf("%d%d%d",&n,&s,&m);
    bool ok=0;
    int pos=0;
    for(int i = 0; i < n; ++i){
        int l,r;
        scanf("%d%d",&l,&r);
        int k = l-pos;
        if( k>=s )
            ok=1;
        pos=r;
    }
    if(m-pos>=s) ok=1;
    if(ok) cout<<"YES";
    else cout<<"NO";
    cout<<"\n";
}
int main(){

    int T;
    cin>>T;
    while(T--){
        solve();
    }
}

D

题目大意:给定字串字符s t s某些字符可以修改 能否通过修改s st t是s子序列

思路:两个指针扫一遍,? 或者能匹配就让第二个指针往前跑,最后判断第二个指针跑到尾了

#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>

using namespace std;

void solve(){
    string s,t;
    cin>>s>>t;
    int j=0;

    for(int i = 0; i < s.size(); ++i){
        if(s[i] == '?' ){
            if(j < t.size()){
                s[i] = t[j];
                ++j;
            }
            else {
                s[i] = 'a';
            }
        }
        else if( s[i] == t[j] and j<t.size()){
            ++j;
        }
    }
    if(j == t.size()) cout<<"YES"<<"\n"<<s;
    else cout<<"NO";
    cout<<"\n";
}
int main(){
    int _;
    cin>>_;
    while(_ --){
        solve();
    }
}

E:

题意:写下L,L+1,...R-1,R个数字,操作他,让一个数乘以三,另一个除以三。直到所有为0 求最小的操作次数

思路:先让L为0 ans 加上操作次数 观察到[3,8] opt=2,[9,26]opt=3 只需要计算区间长度乘以区间对应的opt次数就可

#include <iostream>
#include <cmath>
#include <cstdio>
#define lld long long
using namespace std;
int f(int x){
    int ans=0;
    while(x!=0){
        x/=3;
        ans++;
    }
    return ans;
}

void solve(){
    int L,R;
    cin>>L>>R;
    int K = f(L);
    int M = f(R);
    lld ans=0;
    int a[50],b[50];
    for(int i=0;i<=32;++i){
        a[i] = pow(3,i);
        b[i] = pow(3,i+1)-1;
    }
    ans+=2*f(L);
    int pos=L+1;
    for(int i=f(L+1) ; i <= M; ++i){
        //printf("ans=%d ",ans);
        int pos2 = b[i-1];
        if(pos2>R){
            
            pos2=R;
            //printf("pos=%d pos2=%d \n",pos,pos2);
            ans+=(pos2-pos+1)*i;
            break;
        }
        else {
            //printf("pos=%d pos2=%d \n",pos,pos2);
            ans+=(pos2-pos+1)*i;
            pos = a[i];
        }
        
    }
    cout<<ans<<"\n";
}

int main(){
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}
// 2 3 4 5 6 7 8 9 10 11 12 
// 1 2 2 2 2 2 2 3 3  3   3
// 14+12 = 22

F:

大意:

思路:

标签:964,int,Codeforces,pos,++,cnt2,ans,Div,include
From: https://www.cnblogs.com/Phrink734/p/18348842

相关文章

  • Codeforces Round 964 (Div. 4) D. Slavic's Exam
    题目链接:https://codeforces.com/contest/1999/problem/D题目描述Slavic的考试非常难,需要您的帮助才能通过。以下是他正在努力解决的问题:存在一个字符串s,它由小写英文字母和可能零个或多个“?”组成。Slavic被要求将每个“?”更改为小写英文字母,使得字符串t成为字符串s的......
  • Codeforces Round 962 (Div. 3)
    A.Legs-------------------------------------题解------------------------------经典鸡兔同笼,数据范围不大,跑暴力就行点击查看代码#include<bits/stdc++.h>usingnamespacestd;intmain(){intt;cin>>t;while(t--){intn;cin>......
  • 题解:Codeforces Round 964 (Div. 4) D
    D.Slavic'sExamtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputSlavichasaverytoughexamandneedsyourhelpinordertopassit.Hereisthequestionheisstrugglingwith:Ther......
  • 题解:Codeforces Round 964 (Div. 4) C
    C.Showeringtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputAsacomputersciencestudent,Alexfacesahardchallenge —showering.Hetriestoshowerdaily,butdespitehisbestefforts......
  • Codeforces Round 964 (Div. 4)
    比赛链接:CodeforcesRound964(Div.4)A思路    水题代码#include<iostream>usingnamespacestd;#definelllonglonginlineintread(void){intx=0,f=1;charch=getchar();while(ch<'0'||ch>'9'){......
  • 题解:Codeforces Round 964 (Div. 4) A
    A.A+BAgain?timelimitpertest:1secondmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputGivenatwo-digitpositiveinteger\(n\),findthesumofitsdigits.InputThefirstlinecontainsaninteger\(t\)(\(1......
  • Codeforces Round 964 (Div. 4) 补题记录(A~G2)
    难绷事实:Bwa一发A......#include<bits/stdc++.h>#definepbpush_back#defineintlonglongusingnamespacestd;constintN=500100;inta[N];signedmain(){intT;cin>>T;while(T--){intn;cin>>n;strings=......
  • Codeforces Round 964 (Div. 4)
    CodeforcesRound964(Div.4)A计算数位和。voidsolve(){ inta=0,n; cin>>n; while(n)a+=n%10,n/=10; cout<<a<<'\n';}B模拟,直接枚举4种出牌顺序,按题目给的规则判断即可。boolchk(intx1,inty1,intx2,inty2){ intc1=(x1&g......
  • Codeforces Round 963 (Div. 2)
    第一次上蓝名,指不准哪天掉下来就可以第二次蓝名了,好耶B.ParityandSum(CF1993B)首先特判原数组奇偶性相同的情况,奇偶不同时,由于替换过程只能产生奇数,故目标是将所有偶数变成奇数。假设当前选中奇数\(a_i\)和偶数\(a_j\),若\(a_i<a_j\),第一次操作时\(a_i:=a_j+a_i\),故最多......
  • CodeForces - 765F
    不妨套用P9058的套路,记点对\((i,j),a_i\gea_j\)被支配当且仅当存在\(i<k<j\),满足\(a_i\gea_k\gea_j\),同样,猜测对于\(i\),不被支配的点对\((k,i)\)只满足\(k<i\)最大且\(a_k>a_i\)。证明不妨使用反证法,记\(pre\),满足\(pre<j<i\)且\(a_{pre},a_j>a_i\),假设\((p......