首页 > 其他分享 >Educational Codeforces Round 159 (Rated for Div

Educational Codeforces Round 159 (Rated for Div

时间:2024-01-26 19:14:18浏览次数:20  
标签:std boy Educational Rated 159 Lazy long int define

Educational Codeforces Round 159 (Rated for Div. 2)

A Binary Imbalance

题目大意

给定一个长度为n的一个01字符串,我们执行以下操作:
s[i]!=s[i+1]在中间插入0
问:是否可以实现0的个数大于1的个数

解题思路

由题意可以明显看出只要有0就可以实现。下面简单分析下:

  1. 0的个数大于0,1111110我们可以在子串10中间一直插入0
  2. 0的个数为0时, 11111111不可能在字符串中插入0

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    for(auto i : s)
        if(i == '0'){
            std::cout << "YES" << endl;
            return;
        }
        std::cout << "NO" << endl;
}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}

B Getting Points(贪心)

题目大意

n天里面要获得p分,可以通过两个路径获取分数:

  1. 每天上一堂课,可获得i分.
  2. 进行一次实践,可获得t分,但是实践每七天才会有一个, 每一天最多可以做两个实践

其中, 一天可以选择休息或者学习, 问最多可以休息多少天.

解题思路

可以将所有任务放在最后几天

代码

(大佬们指点一下)

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    int n, p, L, t;
    std::cin >> n >> p >> L >> t;
    int l = 1, r = n, ans =0 ;
    while(l <= r){
        int mid =(l + r)>>1;
        if((n - mid + 1)* L +std::min((n + 6) / 7,(n - mid + 1)* 2 ) * t>= p) ans = mid ,l = mid + 1;
        else r = mid - 1;
    }
    std::cout << ans - 1 << endl;
}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}

C Insert and Equalize

题目大意

给你一个整数数组 a[1],a[2],...,a[n]所有元素都是不同的。

首先,要求你在这个数组中再插入一个整数 a[n+1],a[n+1] 不应等于 a1,a2,...,an。

然后,你必须使数组中的所有元素相等。一开始,你选择一个正整数x(x\>0 )在一次操作中,你将 x 恰好加到数组的一个元素上。
注意,所有操作中 x 都是相同的
在你选择 a[n+1]x 之后,使所有元素相等的最小操作次数是多少?

解题思路

假设数组a 中有元素x, y, z (三者互不相等, 其中 z 最大) , 那么我们就需要找到一个数w,使得 x+k1*w=z, y+k2*w=z
显然就可以看出一个性质w=gcd(abs(x-y), abs(y-z))
就这样我们找到了题目中的x,接下来, 我们需要找插入的a[n+1]
ma=max(a),因为元素互不相等, 我们就需要找插入比mak*w 和比mak*w的两个数,
分别重新找出最大值, 并计算所有元素加到ma的次数
输出两种情况下最小的次数.

代码

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    int n;
    std::cin >> n;
    std::vector<int> a, b;
    std::map<int , int> mp;
    for(int i = 0 ; i < n ; i ++){
        int x;
        std::cin >> x,a.push_back(x), b.push_back(x), mp[a[i]] = 1;
    }

    int w = unique(a.begin (), a.end()) - a.begin ();
    if(w == 1){
        std::cout << 1 << endl;
        return ;
    }
    int o = abs(a[1] - a[0]);
    for(int i = 2 ; i < n ; i ++)
        o = std::__gcd(abs(a[i] - a[i - 1]), o);
    // std::cout << o << endl;
    int cnt = 0;
    int k1 = *std::max_element (a.begin (), a.end ());
    while(true){
        cnt ++;
        if(mp[k1 - cnt * o] != 1){
            a.push_back (k1 - cnt * o);
            break;
        }
    }
    k1 = *std::max_element (a.begin (), a.end ());
    int ans1 = 0, ans2 = 0;
    for(int i = 0 ; i < (int)a.size(); i ++)
        ans1 += abs(a[i] - k1) / o;
    cnt = 0;
    int k2 = *std::max_element (b.begin (), b.end ());
    while(true){
        cnt ++;
        if(mp[k2 + cnt * o] != 1){
            b.push_back (k2 + cnt * o);
            break;
        }
    }
    k2 = *std::max_element (b.begin (), b.end ());
    for(int i = 0 ; i < (int)b.size(); i ++)
        ans2 += abs(a[i] - k2) / o;
    std::cout << std::min(ans1, ans2) << endl;

}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}

D Robot Queries

题目描述

给一个长度为n 的字符串和q次询问, 机器人开始在(0,0)
机器人可以执行四条指令:

  1. U-- 从点(x,y) 移动到 (x,y+1)
  2. D-- 从点(x,y) 移动到 (x,y−1)
  3. L--从点 (x,y) 移动到 (x−1,y)
  4. R--从点 (x,y) 移动到 (x+1,y)
    每次询问四个数x, y, l, r ,
    判断机器人是否访问过点(x, y),但字符串l 到 r 的字串是相反的.

代码

(TLE 13)

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    int n, q;
    std::cin >> n >> q;
    std::string s;
    std::cin >> s;
    s = " " + s;
    while(q --){
        int x = 0, y = 0, N, M, l, r;
        std::cin >> N >> M >> l >> r;
        std::string str(s);
        bool f = false;
        reverse (str.begin() + l, str.begin () + r + 1);
        // std::cout << str << endl;
        for(int i = 1; i < (int) str.size() ;i ++){
            if(x == N && y == M){
                std::cout << "YES" << endl;
                f = true;
                break;
            }
            if(str[i] == 'U')y ++;
            else if(str[i] == 'D') y --;
            else if(str[i] == 'L') x --;
            else x ++;
            if(x == N && y == M){
                std::cout << "YES" << endl;
                f = true;
                break;
            }
            // std::cout << x << " " << y << endl;
        }
        if(!f)
            std::cout << "NO" << endl;
    }
}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
    // std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}

标签:std,boy,Educational,Rated,159,Lazy,long,int,define
From: https://www.cnblogs.com/Lazyboyjdj/p/17990494

相关文章

  • Educational Codeforces Round 160 (Rated for Div
    ARatingIncreas题目大意给定一个数字,让我们拆分成两个数,这两个数满足以下条件:a<b.两个数没有前缀0.问:输出满足条件的数a,b.解题思路直接暴力循环这个数的位数次,若满足a<b,再判断两个数的位数和是否与拆分前相同.代码#include<bits/stdc++.h>#defin......
  • Educational Codeforces Round 161 (Rated for Div
    ATrickyTemplate题目描述给一个数字n和三个长度为n的字符串a,b,c。找一个模板使得字符串a,b匹配,而c不匹配,是否存在这样一个模板.匹配的定义是:当模板字母为小写时,两个字符串字符相同,为大写时,两个字符不同,这样的两个字符串则匹配解题思路我们可以直接得出当a字符串......
  • P4159 [SCOI2009] 迷路 题解
    P4159[SCOI2009]迷路搬运工题目链接首先我们先考虑这道题的弱化版如何处理。假如所有的边权都是零和一。这时他们的边权可以看做这两个点走一步到达之间的方案数。而对于走t步,我们可以推出下列式子,\(f_{i,j}\)表示从节点\(i\)到节点\(j\)的方案数。\[f_{i,j}=\su......
  • P1597 语句解析
    1.题目介绍语句解析题目背景木有背景……题目描述一串长度不超过\(255\)的PASCAL语言代码,只有\(a,b,c\)三个变量,而且只有赋值语句,赋值只能是一个一位的数字或一个变量,每条赋值语句的格式是[变量]:=[变量或一位整数];。未赋值的变量值为\(0\)输出\(a,b,c\)的值。......
  • 洛谷题单指南-模拟和高精度-P1591 阶乘数码
    原题链接:https://www.luogu.com.cn/problem/P1591题意解读:此题核心就是通过高精度*低精度计算阶乘,然后统计数码个数即可,直接给出代码。100分代码:#include<bits/stdc++.h>usingnamespacestd;vector<int>mul(vector<int>&a,intb){vector<int>result;intt......
  • (区间覆盖问题)P5019 [NOIP2018 提高组] 铺设道路和Educational Codeforces Round 158 (
    区间覆盖问题这里EducationalCodeforcesRound158(RatedforDiv.2)b题和[NOIP2018提高组]铺设道路两道典型题目,本质是相同的。这里由于题目多次出现,特此记录。解题思路:首先我们得对区间做划分,那么划分思路可以是从小到大也可以是从大到小的异常点来做划分(我这是由大到......
  • P1597 语句解析
    题目链接:该题的读入方式值得学习:连续读入若干条相同格式的语句,可以考虑\(\sfwhile...scanf...!=EOF\)的形式。由于赋值语句可能是将变量赋值给变量或者将值赋给变量,因此在这里需要对\(\rms_2\)是否是数字作讨论。#include<cstdio>chars1,s2;inta[3];intmain(){......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    基本情况A犯病卡半小时。主要就是太着急,题目没有彻底分析清楚就开始想一些错误做法。C最优想法出来的慢。E比较好想。C.ClosestCitiesProblem-C-Codeforces就,显然是能走最近城市就走,不行就不走。一开始弄了一个自作聪明的预处理,但实际上每次查询还是\(\operatorn......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    A.TrickyTemplate思维有点难转过来,而且当时在C也能匹配c这卡了很久#include<bits/stdc++.h>usingnamespacestd;voidsolve(){ intn; cin>>n; stringa,b,c; cin>>a>>b>>c; intcnt=0; intf=0; for(inti=0;i<n;i++){ if(a[i]!=c[i]&&a......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    题目链接:EducationalCodeforcesRound161(RatedforDiv.2) PS:A开的很快,B读个假题意,C又想歪了,导致E没时间写,最后十分钟开E思路对了但是没时间了,赛后很快过了。。。A.TrickyTemplate题意:定义模板串t与字符串s:1:如果模板串的某一项为小写字母,那么模板串与字符串的该......