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

Codeforces Round 964 (Div. 4)A~G1

时间:2024-09-25 23:48:12浏览次数:1  
标签:964 const cout int ll Codeforces long cin Div

Codeforces Round 964 (Div. 4)A~G1

A. A+B Again?

签到

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    
    int n; cin>>n;
    for(int i = 1.;i <= n; i++)
    {
        int x; cin>>x;
        cout<<x%10 + x/10<<"\n";
    }


    return 0;
}

B. Card Game

签到,但注意一下平局

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    while(t--)
    {
        int a1,a2,b1,b2;
        cin>>a1>>a2>>b1>>b2;
        int win = 0;
        //1 1 , 2 2
        //1 2 , 2 1
        //2,1 , 1 2
        //2 2 , 1 1

        if((a1 > b1 && a2 >= b2)||(a1 >= b1 && a2 > b2))win++;

        if((a1 > b2 && a2 >= b1)||(a1 >= b2 && a2 > b1))win++;

        if((a2 > b1 && a1 >= b2)||(a2 >= b1 && a1 > b2))win++;

        if((a2 > b2 && a1 >= b1)||(a2 >= b2 && a1 > b1))win++;

        cout<<win<<"\n";
    }


    return 0;
}

C. Showering

因为没有交集,那么直接左断点排序然后一个个判断就行了。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    while(t--)
    {
        int n,s,m; cin>>n>>s>>m;
        set<pair<ll,ll>>st;
        for(int i = 1;i <= n; i++)
        {
            ll l,r; cin>>l>>r;
            st.insert({l,r});
        }
        ll last = 0,now = 0;
        bool fg = false;
        for(auto [l,r] : st)
        {
            now = l;
            if(now-last >= s){
                fg = true;
                break;
            }
            last = r;
        }

        if(m - last >= s)fg = true;
        cout<<(fg?"YES":"NO")<<"\n";
    }


    return 0;
}

D. Slavic's Exam

注意一下是子序列。然后对于目标串每一个字母进行判断是否能存在即可。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    while(t--)
    {
        string s,t;
        cin>>s>>t;
        int lens = s.size();
        int lent = t.size();
        s = "?" + s;
        t = "?" + t;

        int cnt = 0;
        for(int i = 1;i <= lens; i++)
            cnt += (s[i]=='?');
        if(cnt >= t.size()){
            cout<<"YES\n";
            int j = 1;
            for(int i = 1;i <= lens; i++)
            {
                if(s[i] == '?' && j <= lent)s[i] = t[j],j++;
                else if(s[i] == '?')s[i] = 'a';
                
                cout<<s[i];
            }
            cout<<"\n";
            continue;
        }

        bool ok = true;

        int j = 1;
        for(int i = 1;i <= lent; i++)
        {
            // cout<<"i = "<<i<<" j = "<<j<<"\n";
            while((s[j] != t[i] && s[j] != '?') && j <= lens){
                // cout<<s[j]<<" "<<t[i]<<"\n";
                j++;
            }
            // cout<<"!!!j = "<<j<<"\n";
            if((s[j] != t[i] && s[j] != '?') || j > lens){
                
                // cout<<"####\n";
                // cout<<s[j]<<" "<<t[i]<<"\n";
                ok = false;
                break;
            }
            s[j] = t[i];
            j++;
        }

        cout<<(ok?"YES":"NO")<<"\n";
        if(ok){
            for(int i = 1;i <= lens; i++)
            {
                if(s[i] == '?')s[i] = 'a';
                cout<<s[i];
            }
            cout<<"\n";
                
        }
        
        
        

    }


    return 0;
}

E. Triple Operations

题意:给你一段连续数[l,r]。你可以选择任意两个数\(x,y\)进行操作,使得\(x\)变成\(3x\),\(y\)变成\(\lfloor\dfrac{y}{3}\rfloor\)。

问最少变多少次使得所有都变成0?

思路:很容易想到是先把最小先变成0,然后再操作其他的,这样不会有其他数变大了。

可以用前缀和先预处理出前\(i\)个数变为0的次数\(s[i]\)。对于\([l,r]\)答案就是:最小的数变为0的次数\(\times2\),加上\(s[r]-s[l]\)。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
ll s[N];
int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    for(int i = 1;i < N; i++)
    {
        int x = i;
        int cnt = 0;
        while(x)
        {
            x /= 3;
            cnt++;
        }
        s[i] = s[i-1] + cnt;
    }
    
    while(t--)
    {
        int l,r; cin>>l>>r;
        int cnt = s[l]-s[l-1];
        cnt *= 2;
        cnt += s[r]-s[l];
        cout<<cnt<<"\n";
    }


    return 0;
}

F. Expected Median

思路:因为只有0和1,那么中位数要么是0要么是1。要算中位数的和,0就不用管了。考虑什么时候1会是中位数,很显然是\(1\)的个数\(\ge0\)的个数的时候。然后用组合数学选出要哪几个\(1\)搞一搞就行了。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

ll f[N],infact[N];

ll qmi(ll a, ll b, ll mod)
{
    ll ans = 1 % mod;
    while(b)
    {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}


void init()
{
    f[0] = infact[0] = 1;
    for(int i = 1; i <= N; i++)
    {
        f[i] = i * f[i - 1] % mod;
        infact[i] = infact[i - 1] * 1ll * qmi(i, mod-2, mod) % mod;
    }
}

ll C(ll a,ll b)
{
    return f[a] * infact[b] % mod * infact[a - b] % mod;
}


int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    init();
    while(t--){
        int n,k; cin>>n>>k;
        int cnt0 = 0,cnt1 = 0;
        for(int i = 1;i <= n; i++)
        {
            int x; cin>>x;
            cnt0 += (x==0);
            cnt1 += (x==1);
        }

        int mid = (k+1)/2;
        ll ans = 0;
        for(int i = mid; i <= min(cnt1,k); i++)
        {
            // cout<<"i = "<<i<<"\n";
            // cout<<"C(cnt1,i) = "<<C(cnt1,i)<<"\n";
            if(k-i<=cnt0)
                ans = (ans + C(cnt1,i)*C(cnt0,k-i)%mod) % mod;
        }

        cout<<ans<<"\n";

    }


    return 0;
}

G1. Ruler (easy version)

思路:是一个交互题呀。最多问10次的话,很容易想到是log级别的,二分。

简化一下问题,如果只有一个维度,怎么做呢?是不是突然觉得容易很多了。

如果当前比实际的大说明有问题,如果等于的话说明是正常的。这个就很好写啦。

但是你会想这个是二维的呀,怎么办呢?让一个维度是1就行啦。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    // ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    while(t--)
    {
        int l = 2,r = 1000;
        while(l < r){
            int mid = (l + r)>>1;
            cout<<"? 1 "<<mid<<endl;
            int in; cin>>in;
            if(in == mid)l = mid + 1;
            else r = mid;
        }
        cout<<"! "<<l<<endl;
    }

    return 0;
}

标签:964,const,cout,int,ll,Codeforces,long,cin,Div
From: https://www.cnblogs.com/nannandbk/p/18432545

相关文章

  • Codeforces Round 973 (Div. 2)
    C.PasswordCracking(C)若字符串只向一个方向延伸,则一定能通过\(2n\)次询问获得结果;可以先向后猜测,当该侧继续添加字符1与0都不符合要求时、说明已经到达字符串末端,继续询问前缀即可。voidsolve(){intn;cin>>n;strings="";boolflag=0;w......
  • Codeforces Round 971 (Div. 4)A~G1
    CodeforcesRound971(Div.4)A~G1A.Minimize!签到不多说。//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constintmod=1e9+7;constintN=2e5+10;intmain(){ ios::sync_with_stdio(false......
  • Codeforces Round 974 (Div. 3)题解记录
    A.RobinHelps签到模拟,遍历一遍即可,注意没钱时不给钱。\(O(n)\)#include<iostream>#include<set>#include<map>#include<vector>#include<algorithm>#include<bitset>#include<math.h>#include<string>#include<string.h>#......
  • Codeforces Round 959 (Div. 1 + Div. 2) C. Hungry Games题解
    CodeforcesRound959(Div.1+Div.2)C.HungryGames题解题目链接大致题意:给定一个长度为n的数组,并且给出一对l,r表示一个区间,如果∑i......
  • Codeforces Round 974 (Div.3) 题解
    CodeforcesRound974(Div.3)题解A.RobinHelps模拟按照题意模拟即可。voidShowball(){intn,k;cin>>n>>k;intcur=0,ans=0;for(inti=0;i<n;i++){intx;cin>>x;if(x>=k)cur+=x;elseif(!x){if(cur>=1)cu......
  • codeforces round 974(div.3) D(学会灵活拆分数据)
    解题历程:首先想到的是用数组记录,遍历每一个任务的区间,对区间内的数值加1,比如对于发生在4和8天之内的任务,a[4]++,a[5]++……a[8]++。然后用双指针,记录持续天数的开始下标和结束下标,以l和l+d为边界的窗口遍历每一天,若是最高位寻找任务最多的一天,和区间最大值最小的一天。后来发现......
  • p标签不能嵌套div,h1~h6,p,如果嵌套浏览器会如何解析
    有时候做项目会不小心用p嵌套div,发现控制不了样式,我们放到最后去讲p嵌套div的问题首先,我们先用p标签来嵌套h1~h6,这里我选择h1(h1~h6测试结果都一样),上代码及效果图让我们看下浏览器如何解析我们发现,浏览器把h1标签给单独摘出来了,并且多了个p标签,导致这样的原因:看代码图:首......
  • Codeforces Round 973 (Div. 2)
    A.Zhan'sBlender有\(n\)个水果,每秒可以消耗\(\min\{x,y\}\)个,问需要多少时间。整数除法的上取整操作即可。点击查看代码#include<bits/stdc++.h>usingnamespacestd;#definelllonglong#defineullunsignedlonglongintread(){intx=0;boolf=......
  • Codeforces Round 972(Div.2)题解
    CodeforcesRound972(Div.2)题解A.SimplePalindrome贪心贪心,尽可能元素数量平均,并且相同字母放在一起。#include<bits/stdc++.h>usingnamespacestd;#definefffirst#definesssecond#definepbpush_back#defineall(u)u.begin(),u.end()#defineendl'\n'#de......
  • Codeforces Round 973 (Div.2) A-E题解
    CodeforcesRound973(Div.2)A-E题解比赛传送门A.Zhan'sBlender数学显然答案为\(\lceil\frac{n}{min(x,y)}\rceil\)。#include<bits/stdc++.h>usingnamespacestd;#definefffirst#definesssecond#definepbpush_back#defineall(u)u.begin(),u.en......