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

Codeforces Round 928 (Div. 4)

时间:2024-02-20 20:11:36浏览次数:28  
标签:std int Codeforces long 928 while solve Div define

Codeforces Round 928 (Div. 4)

比赛链接

A. Vlad and the Best of Five

思路

就是统计字符A和字符B的个数,将个数多的那个输出出来

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()

#define int long long

void solve(){
    string s;
    cin>>s;
    int ans1=0,ans2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            ans1++;
        }
        else{
            ans2++;
        }
    }
    cout<<(ans1>ans2?'A':'B');
    cout<<'\n';

    
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

B. Vlad and Shapes

思路

就是判断数字1组成的是正方形还是三角形,由于他要求组成的三角形的的特殊性,这里我是比较了一下围成的图形的底和高,如果相等就是正方形,如果不等那就是三角形,但是如果不限制形状是不可以这样做的

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()

#define int long long

void solve(){
    int n; cin>>n;
    std::vector<string> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int hmin=100,hmax=-1;
    int dmin=100,dmax=-1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i][j]=='1'){
                hmin=min(hmin,i);
                hmax=max(hmax,i);
                dmin=min(dmin,j);
                dmax=max(dmax,j);
            }
        }
    }
    if((dmax-dmin)==(hmax-hmin)){
        cout<<"SQUARE"<<endl;

    }
    else{
        cout<<"TRIANGLE"<<endl;
        return ;
        
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

C. Vlad and a Sum of Sum of Digits

思路:

这个题就是预处理一下数字,因为本题的限制是0.5s,所以我们不能每次都去找数字,只能一次性做好,再用O(1)的时间去查询,但是我一开始预处理时候用的字符串方式也超时了,这里我把字符串代码也粘贴出来,希望大家给出意见

Code

//TLE
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()
const int N=2e5+10;
int a[N];
#define int long long
void init(){
    int l=1;

    for(int i=1;i<=N;i++){
        a[i]=a[i-1];

        string s=to_string(l);
        for(int j=0;j<s.size();j++){
            a[i]+=(s[j]-'0');

        }
        l++;

    }
}
void solve(){
    int n;
    cin>>n;
    cout<<a[n]<<endl;
    

}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    init();

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

//AC
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()
const int N=2e5+10;
int a[N];
#define int long long
void init(){
    for(int i = 1; i <= 200000; i ++){
        int x = i;
        while(x){
            a[i] += x % 10;
            x /= 10;
        }
    }
    for(int i = 1; i <= 200000; i ++){
        a[i] += a[i - 1];
    }
}
void solve(){
    int n;
    cin>>n;
    cout<<a[n]<<endl;
    

}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    init();

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;

}

E. Vlad and an Odd Ordering

思路

因为每次都是执行完当前的(n+1)/2张牌,并且都是数字都是有一定规律的,所以可以模拟一下就行

Code

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin()+1,x.end()

#define int long long

void solve(){
    int n,k; cin>>n>>k;
    int ans=0;
    int x=1;
    int now=(n+1)/2;
    while(now<k){
        k-=now;
        n/=2;
        x*=2;

        now=(n+1)/2;
    }
    // int val=2*k-1;
    ans=x*(2*k-1);
    cout<<ans<<endl;
    /**/

}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);

    int T = 1;
    std::cin >> T;
    while (T--) solve();

    return 0;
}

标签:std,int,Codeforces,long,928,while,solve,Div,define
From: https://www.cnblogs.com/du463/p/18023970

相关文章

  • The number of divisors(约数) about Humble Numbers
    Anumberwhoseonlyprimefactorsare2,3,5or7iscalledahumblenumber.Thesequence1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,...showsthefirst20humblenumbers.Nowgivenahumblenumber,pleasewriteaprogramtocal......
  • Codeforces 1806E Tree Master
    考虑一个最基础的暴力,就是直接记忆化搜索暴力往上跳。但是能发现如果一层的节点数过多,状态数太多,就寄了。再考虑一个基础的暴力,就是直接跳。但是如果要跳的层数过多,就寄了。考虑结合一下,根号分治。对于一层内节点数\(\le\sqrt{n}\)的记录下每两个点间的答案。对于节点数......
  • Codeforces Round 928(Div. 4)
    Dashboard-CodeforcesRound928(Div.4)-Codeforces第一次参加CF,最后一道题连题都没读,下次不会就跳,菜是原罪A:找字符串中A,B数量,遍历一下最后比较即可B:判断是三角形还是正方形,题目表示除了正方形就是三角形,所以直接判断是不是正方形,用ans数组记录每一行1的个数,然后从大......
  • Codeforces Round 900 (Div. 3)
    题目A.只要k出现过就是YES#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10;#defineinf0x3f3f3f3fvoidsolve(){intn,k;cin>>n>>k;map<int,int>mp;for(inti=0,x;i<n;i++){cin......
  • Codeforces Round 928 (Div. 4) (小白的复盘)
    A.VladandtheBestofFive思路:给你一个长度字符串只包含A和B输出最多的字符解法:按题意来Code:#include<bits/stdc++.h>usingnamespacestd;intmain(){intt;cin>>t;while(t--){strings;cin>>s;intcnt=0;fo......
  • Codeforces Round 928 (Div. 4)(A、B、C、D、E、G)
    目录ABCDEGA统计A、B输出#include<bits/stdc++.h>#defineintlonglong#definerep(i,a,b)for(inti=(a);i<=(b);++i)#definefep(i,a,b)for(inti=(a);i>=(b);--i)#definepiipair<int,int>#definelllonglong#definedbdouble#de......
  • Codeforces Round 928 (Div. 4)
    总结一下最近:感觉过于追求进度了,没有好好的把每题都吃透消化,然后有点依赖题解了,没有好好的思考...B.VladandShapesB题输入二维数组的时候不可以直接两个for循环然后cin,要读入char,再转为数字赋值给二维数组,因为他读入的时候不带有空格而int是要有空格的,这样子比如读000就把它......
  • CF-928(已更新:B C E)
    CF-928排名四千多,目前为止排名最高的一场~E题我赛时基本上是猜的结论(但是也推了快一小时才想到有这个可能性),因此目前只能放个码在这(⊙﹏⊙)D的话问了学长思路,正在补了0-^-0……但是上一场牛客打得特别烂(⊙﹏⊙),还是等我补了牛客的再更新吧-^-B分析观察它的性质,答案为正方......
  • Codeforces Round 924 (Div. 2)
    目录写在前面ABCDEF写在最后写在前面比赛地址:https://codeforces.com/contest/1928。终于把欠下的一堆题补上了呃呃天使骚骚共通线什么构式呃呃,一周目就想走老师线直通单身笑死我了。A签到。发现等分后重新拼接可以得到\(\frac{x}{2}\times2y\)与\(\frac{y}{2}\times2......
  • Codeforces Round 927 (Div. 3)(A~F)
    目录ABCDEFA第一个遇到连续两个荆棘的地方就不能再赢金币了。所以统计连续两个荆棘之前的所有金币#include<bits/stdc++.h>#defineintlonglong#definerep(i,a,b)for(inti=(a);i<=(b);++i)#definefep(i,a,b)for(inti=(a);i>=(b);--i)#definepiipai......