Codeforces Round #748 (Div. 3)

Codeforces Round #748 (Div. 3)

A. Elections

思路分析:

  • 令当前值比最大值大即可,如果最大值是它自己,就输出(0)

代码

#include
using namespace std;
pair a[3];
int ans[3];
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                for (int i = 0; i < 3; i++)
                        cin >> a[i].first, a[i].second = i;
                sort(a, a + 3);
                for (int i = 0; i < 3; i++)
                {
                        if (i == 0)
                        {
                                ans[a[i].second] = a[2].first - a[0].first + 1;
                        }
                        else if (i == 1)
                        {
                                ans[a[i].second] = a[2].first - a[1].first + 1;
                        }
                        else
                        {
                                if (a[2].first == a[1].first)
                                {
                                        ans[a[i].second] = 1;
                                }
                                else
                                        ans[a[i].second] = 0;
                        }
                }
                for (int i = 0; i < 3; i++)
                {
                        cout << ans[i] << ' ';
                }
                cout << endl;
        }
        return 0;
}

B. Make it Divisible by 25

思路分析:

  • 一开始以为和上次make power of 2一样,然后发现不对劲,想到了结论,25是5的倍数,那么我们剩下的数最后一位必定为5或者0,所以我们一直删到最后一位为5或者0为止。
  • 然后如果为25的倍数的话,末尾两位必定是25,50,75,00,所以我们就分情况取最小值即可。
  • 其实官方题解的最简单,我就建议不要看我这个做法了。

代码

#include
using namespace std;
int a[2] = {2, 7};
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                string s;
                cin >> s;
                string c = s;
                int mincnt = 0;
                //以5为最后一位
                for (int i = s.size() - 1; i >= 0; i--)
                {
                        if (s[i] != '5')
                        {
                                s.erase(i);
                                mincnt++;
                        }
                        //找到5
                        else
                                break;
                }
                for (int i = s.size() - 2; i >= 0; i--)
                {
                        if (s[i] != '2' && s[i] != '7')
                        {
                                mincnt++;
                                s.erase(i);
                        }
                        else
                                break;
                }
                int temp = 0;
                for (int i = c.size() - 1; i >= 0; i--)
                {
                        if (c[i] != '0')
                        {
                                c.erase(i);
                                temp++;
                        }
                        //找到5
                        else
                                break;
                }
                for (int i = c.size() - 2; i >= 0; i--)
                {
                        if (c[i] != '5' && c[i] != '0')
                        {
                                temp++;
                                c.erase(i);
                        }
                        else
                                break;
                }
                cout << min(mincnt, temp) << endl;
        }
        return 0;
}

C. Save More Mice

思路分析:

  • 这题其实就是贪心吧,让离洞最近的老鼠先逃即可,因为老鼠和猫的相对速度为(1)。
  • 注意更新猫的位置即可。

代码

#include
using namespace std;
vector a;
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                a.clear();
                int n, k;
                cin >> n >> k;
                for (int i = 0; i < k; i++)
                {
                        int x;
                        cin >> x;
                        a.push_back(x);
                }
                sort(a.begin(), a.end());
                int ans = 0;
                int x = 0;
                for (int i = a.size() - 1; i >= 0; i--)
                {
                        if (x < a[i])
                        {
                                x += (n - a[i]);
                                ans++;
                        }
                        else
                                break;
                }
                cout << ans << endl;
        }
        return 0;
}

D1. All are Same

思路分析:

  • 因为最后要把所有数变为一个数,那么肯定是把所有数变成当前数组的最小值即可。
  • 那么如何求这个减去的数的最大值呢?
  • 实际上也就是所有数和最小值的GCD了。

代码

#include
using namespace std;
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int t;
        cin >> t;
        while (t--)
        {
                int n;
                cin >> n;
                vector a(n);
                for (int i = 0; i < n; i++)
                {
                        cin >> a[i];
                }
                sort(a.begin(), a.end());
                int x = a[0];
                int ans = 0;
                for (int i = 0; i < n; i++)
                {
                        ans = __gcd(ans, a[i] - x);
                }
                if (ans != 0)
                        cout << ans << endl;
                else
                {
                        cout << "-1" << endl;
                }
        }
        return 0;
}

D2. Half of Same

思路分析:

  • 我们可以知道当且仅当当前数组中已经有(n / 2)个数相同输出(-1)。
  • 我们枚举每一个数,也就是说把其他数变为它需要减去多少值保存一下,然后记录原数组中已经有多少个数与它相同,再因数分解一下这个差值,然后遍历它的差值的因数,取使得因数的个数加上原本和它一样的数的个数大于(n / 2)的最大的因数即可。

代码

#include
using namespace std;
set divide(int x)
{
        set q;
        for (int i = 1; i * i > t;
        while (t--)
        {
                int n;
                cin >> n;
                vector a(n);
                for (int i = 0; i < n; i++)
                {
                        cin >> a[i];
                }
                int k = -1;
                for (int i = 0; i < a.size(); i++)
                {
                        int minv = a[i];
                        int same = 0;
                        vector d;
                        for (int j = 0; j < a.size(); j++)
                        {
                                if (a[j] == minv)
                                        same++;
                                else if (a[j] > minv)
                                {
                                        d.push_back(a[j] - minv);
                                }
                        }
                        if (same >= n / 2)
                        {
                                k = INT_MAX;
                                break;
                        }
                        map mp;
                        for (auto x : d)
                        {
                                for (auto xx : divide(x))
                                {
                                        mp[xx]++;
                                }
                        }
                        for (auto x : mp)
                        {
                                if (x.second + same >= n / 2)
                                {
                                        k = max(k, x.first);
                                }
                        }
                }
                cout << (k == INT_MAX ? -1 : k) << endl;
        }
        return 0;
}

E. Gardener and Tree

思路分析:

  • 一开始以为暴力能过就写了个暴力然后T了。然后看了下题解,原来是反向的,也就是说我们也是模拟一下删点过程(把这棵树删完),然后统计一下是在第几轮删去的这个点,最后把删去轮数和(k)比较即可。

代码

#include
using namespace std;
const int maxn = 4e5 + 10;
int degree[maxn];
vector e[maxn];
int n, k, ans;
int vis[maxn];
int dis[maxn];
int main()
{
        int t;
        cin >> t;
        while (t--)
        {
                memset(vis, 0, sizeof(vis));
                memset(degree, 0, sizeof(degree));
                memset(dis, 0, sizeof(dis));
                cin >> n >> k;
                ans = n;
                for (int i = 1; i > u >> v;
                        e[u].push_back(v);
                        e[v].push_back(u);
                        degree[u] += 1;
                        degree[v] += 1;
                }
                queue q;
                for (int i = 1; i  k)
                        {
                                ans++;
                        }
                }
                cout << ans << endl;
        }
        return 0;
}

Original: https://www.cnblogs.com/csu-yuuki/p/15429814.html
Author: zhy-cx
Title: Codeforces Round #748 (Div. 3)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/713459/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 初识CityEngine【转】

    一、CityEngine历史 二、CityEngine建模思想 1、生成城市地块 2、楼层房间切割 3、建模思想、流程 (1)、建筑生成思想 (2)、官方示意流程图 三、CityE…

    技术杂谈 2023年5月31日
    087
  • 前端富文本基础及实现

    在日常生活中我们会经常接触到各种各样的文档格式和形式,其中富文本在文档格式中扮演了重要角色。对于前端而言,富文本产品也层出不穷,其应用也越来越广。 这篇文章将会为大家介绍前端富文本…

    技术杂谈 2023年5月31日
    0107
  • 会话技术 cookie 和 Session(1)

    CookieCookie 属于客户端会话技术,它是服务器发送给浏览器的小段文本信息,存储在客户端浏览器的内存中或硬盘上。当浏览器保存了Cookie 后,每次访问服务器,都会在HTT…

    技术杂谈 2023年6月21日
    0136
  • 方位

    【 方位】 1、《3D数学基础》中,方位被称为 head(y轴)、pitch(x轴)、bank(z轴)。但书上提到 head==yaw,bank==roll。 2、《Real-Ti…

    技术杂谈 2023年5月31日
    087
  • windows挂载NFS共享

    实验环境: NFS主机(192.168.18.10):CentOS7.0 软件包:nfs-utils、rpcbind; 客户机(192.168.18.41):windows ser…

    技术杂谈 2023年7月24日
    082
  • Mac 每次都要执行source ~/.bash_profile 配置的环境变量才生效

    自己在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bash_profile 发现zsh加载的是 ~/…

    技术杂谈 2023年5月31日
    091
  • ​grafana 的主体架构是如何设计的?

    ​grafana 的主体架构是如何设计的? grafana 是非常强大的可视化项目,它最早从 kibana 生成出来,渐渐也已经形成了自己的生态了。研究完 grafana 生态之后…

    技术杂谈 2023年6月1日
    0100
  • 内部类

    当目前某个类现在需要一个只能该类使用的类时 1.能修饰类的权限修饰符只能时 默认不写(default) 和公共(public) 2.内部类私有化 正向思考: 四种权限修饰符常用来修…

    技术杂谈 2023年6月21日
    0104
  • AE2020教程,如何在 After Effects 中使用形状图层构建图形过渡效果?

    Original: https://www.cnblogs.com/123ccy/p/16546561.htmlAuthor: -Mac123-Title: AE2020教程,如何…

    技术杂谈 2023年5月31日
    087
  • SpringBoot整合MybatisPlus基本的增删改查,保姆级教程

    概述 MybatisPlus是国产的第三方插件, 它封装了许多常用的CURDapi,免去了我们写mapper.xml的重复劳动,这里介绍了基本的整合SpringBoot和基础用法。…

    技术杂谈 2023年6月21日
    064
  • [置顶] 开关电源的pcb设计规范

    参数设置相邻导线间距必须能满足电气安全要求印制线的长度和宽度会影响其阻抗和感抗尽量加粗接地线若接地线很细按照电路的流程安排各个功能电路单元的位置在任何开关电源设计中,pcb板的物理…

    技术杂谈 2023年6月1日
    071
  • 集合remove()方法相关问题

    学习集合的过程中,了解到一个有关于remove()方法的有关特性,特此记录 首先remove方法的格式: collection.remove(Object o); 这是指对集合co…

    技术杂谈 2023年7月25日
    076
  • HR-901FH卫星信号安全防护装置-授时安全防护装置

    HR-901FH卫星信号安全防护装置-授时安全防护装置 HR-901FH卫星信号安全防护装置-授时安全防护装置 京准电子科技官微——ahjzsz 产品简介 HR-901FH卫星时空…

    技术杂谈 2023年6月21日
    081
  • PriorityBlockingQueue详解

    PriorityBlockingQueue介绍 【1】PriorityBlockingQueue是一个无界的基于数组的优先级阻塞队列,数组的默认长度是11,也可以指定数组的长度,且…

    技术杂谈 2023年7月24日
    057
  • Docker私有仓库搭建

    Docker私有仓库搭建 1、Docker Registry 网上有很多的 Registry服务器都支持第三方用户注册,而后基于用户名去做自己的仓库,但是使用互联网上的 Regis…

    技术杂谈 2023年6月21日
    094
  • 在线英语词典

    https://dictionary.cambridge.org/dictionary/english-chinese-simplified/ Original: https://…

    技术杂谈 2023年6月1日
    086
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球