当前位置: 首页 > news >正文

Educational Codeforces Round 175 (Rated for Div. 2)

题目链接:https://codeforces.com/contest/2070

A. FizzBuzz Remixed

思路:

要使得x mod 3 == x mod 5,很明显当x是15的倍数时满足

再观察可以知道,当x = 15*k + m (m为0 1 2) 时都满足条件

故可写码了

代码:

//#include <iostream>
//#include <algorithm>
//#include<cstring>
//#include<cctype>
//#include<string>
//#include <set>
//#include <vector>
//#include <cmath>
//#include <queue>
//#include <unordered_set>
//#include <map>
//#include <unordered_map>
//#include <stack>
//#include <memory>
//using namespace std;
//#define ll long long
//#define yes cout << "YES" << endl
//#define no cout << "NO" << endl
//
(0 1 3 4 6 7 9) * 3
//
//void solve()
//{
//    int n;
//    cin >> n;
//    ll ans = 0;
//    ans += (n / 15+1) * 3;
//    for (int j = 0; j < 3; j++)
//    {
//        if (15 * (n / 15) + j > n)
//        {
//            ans--;
//        }
//    }
//    cout << ans << endl;
//}
//
//int main()
//{
//    //for (int i = 0; i <= 1000; i++)
//    //{
//    //    if (i >= 0 && i % 3 == i % 5)
//    //        cout << i << endl;
//    //}
//    cin.tie(0)->sync_with_stdio(false);
//    int t = 1;
//    cin >> t;
//    while (t--)
//    {
//        solve();
//    }
//    return 0;
//}

B. Robot Program

思路:

模拟一下即可,先判断能不能回到0点,如果可以会到0点,那么再判断一下能不能再次回到0点,如果能,就能得到步数k,之后直接除即可

代码:

//#include <iostream>
//#include <algorithm>
//#include<cstring>
//#include<cctype>
//#include<string>
//#include <set>
//#include <vector>
//#include <cmath>
//#include <queue>
//#include <unordered_set>
//#include <map>
//#include <unordered_map>
//#include <stack>
//#include <memory>
//using namespace std;
//#define ll long long
//#define yes cout << "YES" << endl
//#define no cout << "NO" << endl
//
//void solve()
//{
//    ll n, x, k;
//    cin >> n >> x >> k;
//    string s;
//    cin >> s;
//    int time1 = 0;
//    for (int i = 0; i < n; i++)
//    {
//        x += (s[i] == 'L') ? -1 : 1;
//        if (x == 0)
//        {
//            time1 = 1+i;
//            break;
//        }
//    }
//    int time2 = 0;
//    for (int i = 0; i < n; i++)
//    {
//        x += (s[i] == 'L') ? -1 : 1;
//        if (x == 0)
//        {
//            time2 = 1 + i;
//            break;
//        }
//    }
//    ll ans = 0;
//    if (time1 != 0)
//    {
//        ans++;
//        k -= time1;
//        if(time2)
//        ans += k / time2;
//    }
//    cout << ans << endl;
//}
//
//int main()
//{
//    cin.tie(0)->sync_with_stdio(false);
//    int t = 1;
//    cin >> t;
//    while (t--)
//    {
//        solve();
//    }
//    return 0;
//}

C. Limited Repainting

思路:

一道二分+贪心的题目

我们可以二分答案,然后check一下是否满足,那么难点就在于check函数了

现在我们假设答案为mid,那么就有以下几种情况

① s[i] = B

如果a[i] < mid,如果我们还没开始涂,那我们跳过即可,因为最后的答案是取所有a[i]的最大值,此时不涂对答案也没影响,如果我们前面已经涂了,那么再涂这个也无妨,因为涂的越多肯定越好,比如有

BBB

mid mid-1 mid

那我们如果不涂第二个的话,我们就至少需要两次才能满足,但是涂了第二个一次就能连续涂完

否则我们必须涂

② s[i] = R

如果我们还没开始涂,那么直接跳过即可

否则,如果a[i] > mid,我们就不能涂,因为此时答案就不为mid了,否则直接涂就行,理由同上,多涂更好

代码:

//#include <iostream>
//#include <algorithm>
//#include<cstring>
//#include<cctype>
//#include<string>
//#include <set>
//#include <vector>
//#include <cmath>
//#include <queue>
//#include <unordered_set>
//#include <map>
//#include <unordered_map>
//#include <stack>
//#include <memory>
//using namespace std;
//#define ll long long
//#define yes cout << "YES" << endl
//#define no cout << "NO" << endl
//
//void solve()
//{
//    int n, k;
//    cin >> n >> k;
//    string s;
//    cin >> s;
//    vector<int> a(n);
//    for (int i = 0; i < n; i++)
//    {
//        cin >> a[i];
//    }
//    int l = 0, r = 1e9+1;
//    auto check = [&](int mid) -> bool
//        {
//            int cnt = 0;
//            for (int i = 0; i < n; i++)
//            {
//                if (a[i] > mid && s[i] !='R')
//                {
//                    int j = i + 1;
//                    while (j < n && (s[j] == 'B' || a[j] <= mid))
//                    {
//                        j++;
//                    }
//                    i = j - 1;
//                    cnt++;
//                }
//            }
//            return cnt <= k;
//        };
//    while (l < r)
//    {
//        int mid = (l+r) / 2;
//        if (check(mid))
//        {
//            r = mid;
//        }
//        else
//        {
//            l = mid+1;
//        }
//    }
//    cout << r << endl;
//}
//
//int main()
//{
//    cin.tie(0)->sync_with_stdio(false);
//    int t = 1;
//    cin >> t;
//    while (t--)
//    {
//        solve();
//    }
//    return 0;
//}

D. Tree Jumps

思路:

首先要理解题意,我们只能从 当前节点 跳至 非自身子节点 的 节点

那我们可以反过来考虑,对于任意一个节点,有多少方式跳过来

我们可以分层考虑

对于根节点(第一层)只有一种

对于第二层也是只有一种,因为有且只能从根节点跳过来(题目中的特例)

对于第三层的节点,任意一个节点的跳法有 node[i].val = sum[2] - node[node[i].father].val 种

其中sum[i]为第i层所有节点的跳法总和,node[i].val为节点i的跳法

同理,对于第n层也是这样

那么最后的答案就为每层sum之和

(这里要注意大数取模)

代码:

//#include <iostream>
//#include <algorithm>
//#include <cstring>
//#include <cctype>
//#include <string>
//#include <set>
//#include <vector>
//#include <cmath>
//#include <queue>
//#include <unordered_set>
//#include <map>
//#include <unordered_map>
//#include <stack>
//#include <memory>
//using namespace std;
//
//const int MOD = 998244353;
//
//struct Z {
//    long long val;
//    Z(long long v = 0) : val(v% MOD) {
//        if (val < 0) val += MOD;
//    }
//    Z& operator+=(const Z& other) {
//        val = (val + other.val) % MOD;
//        return *this;
//    }
//    Z& operator-=(const Z& other) {
//        val = (val - other.val + MOD) % MOD;
//        return *this;
//    }
//    Z& operator*=(const Z& other) {
//        val = (val * other.val) % MOD;
//        return *this;
//    }
//    friend Z operator+(Z a, const Z& b) { return a += b; }
//    friend Z operator-(Z a, const Z& b) { return a -= b; }
//    friend Z operator*(Z a, const Z& b) { return a *= b; }
//    friend ostream& operator<<(ostream& os, const Z& z) {
//        return os << z.val;
//    }
//};
//
//struct MyStruct
//{
//    int father = -1;
//    int dep = 1;
//    Z val = 0; // 修改为Z类型
//    int self = 1;
//};
//
//void solve()
//{
//    int n;
//    cin >> n;
//    vector<MyStruct> node(n + 1);
//    int maxdep = 0;
//    node[1].val = 1; // 隐式转换为Z
//    for (int i = 2; i <= n; i++)
//    {
//        cin >> node[i].father;
//        node[i].dep = node[node[i].father].dep + 1;
//        node[i].self = i;
//        maxdep = max(maxdep, node[i].dep);
//    }
//    vector<vector<MyStruct>> depnode(maxdep + 1);
//    vector<Z> depSum(maxdep + 1, 0); // 改为vector<Z>
//    for (int i = 1; i <= n; i++)
//    {
//        depnode[node[i].dep].push_back(node[i]);
//    }
//    depSum[1] = 1;
//    for (int i = 2; i <= maxdep; i++)
//    {
//        for (size_t j = 0; j < depnode[i].size(); j++)
//        {
//            if (i == 2)
//                node[depnode[i][j].self].val = 1;
//            else
//                node[depnode[i][j].self].val = depSum[i - 1] - node[depnode[i][j].father].val;
//            depSum[i] += node[depnode[i][j].self].val;
//        }
//    }
//    Z ans = 0; // 改为Z类型
//    for (int i = 1; i <= maxdep; i++)
//    {
//        ans += depSum[i];
//    }
//    cout << ans << endl;
//}
//
//int main()
//{
//    cin.tie(0)->sync_with_stdio(false);
//    int t = 1;
//    cin >> t;
//    while (t--)
//    {
//        solve();
//    }
//    return 0;
//}

相关文章:

  • KTV点歌系统
  • Windows逆向工程入门之MASM浮点数存储机制
  • 小米 SU7 Ultra:科技与性能的极致融合,FPC 隐匿的关键力量【新立电子】
  • 华为hcia——Datacom实验指南——STP工作基本原理及STP/RSTP基本功能配置
  • Python虚拟环境使用指南
  • Http、tcp、https、socket、tomcat、长短连接等总结回顾
  • SpringBoot AI + PgVector向量库 + Openai Embedding模型
  • JAVA安全—手搓内存马
  • JVM--虚拟机
  • 【大模型】什么是蒸馏版大模型
  • 量子计算如何提升机器学习效率:从理论到实践
  • 深度学习的正则化深入探讨
  • Open3D的所有窗口小部件
  • go并发编程
  • STM32定时器超声波测距实验手册
  • 【VxLAN】二、VxLAN-EVPN分布式网关-ensp实验
  • Android Trace埋点beginSection打tag标签,Kotlin
  • 【Linux】命令行参数 | 环境变量(四)
  • Educational Codeforces Round 174 (Rated for Div. 2)
  • 充电枪和充电桩的区别
  • wordpress展示型外贸网站/旺道seo优化软件
  • php网站cms/软文代写自助发稿平台
  • 怎么根据别人的网站做自己的网站/seo搜索引擎优化期末考试
  • 如何做婚介网站/关键词优化公司哪家推广
  • 网站ip地址 a记录/国内seo排名分析主要针对百度
  • 湖南做网站 多少钱磐石网络/公众号推广平台