• AtCoder Beginner Contest 093


    A - abc of ABC

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    char a[5];
    int main() {
        for (int i = 0; i < 3; i++) cin >> a[i];
        sort(a, a + 3);
        for (int i = 0; i < 3; i++) {
            if (a[i] != 'a' + i) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    

    B - Small and Large Integers

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int q;
    LL x, y;
    int main() {
        cin >> q;
        while (q--) {
            cin >> x >> y;
            if(x>y)swap(x,y);
            if(x==y){
                cout << 2 * x - 2 << endl;
                continue;
            }
            else if(x==y+1){
                cout << 2 * x - 2 << endl;
                continue;
            }
            LL c = sqrt(x * y);
            if (c * c == x * y) c--;
            if(c*(c+1)<x*y){
                cout << 2 * c - 1 << endl;
            }
            else
                cout << 2 * c - 2 << endl;
        }
        return 0;
    }
    

    C - Same Integers

    给出abc三个数,现在可以进行如下操作

    一种是选择两个数,将他们都加1

    一种 选择一个数,将其加2

    问多少次操作后可以使得三个数相等

    算出最大的数和两个数差的和,如果是偶数直接除以2

    否则就加上3后除以2即可

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int a[3];
    int main() {
        cin >> a[0] >> a[1] >> a[2];
        sort(a, a + 3);
        int res = a[2] - a[0] + a[2] - a[1];
        if (res & 1) res += 3;
        cout << res / 2 << endl;
        return 0;
    }
    

    D - Worst Case

    给出a和b,需要找出乘积比a*b小的不同组合

    首先假设a<=b

    对于a==b的情况,那么从1到a-1都可以找到对应的值(例如a-1找b+1),对应的1到b-1也可以找到,所以是2*(a-1)

    对于a+1==b的情况,那么也是同样可以找到2*(a-1)

    对于一般的情况,假设(c*c<a*b),那么对于1到c-1,都可以找到对应的值,但是要删去a这一项,如果(c*(c+1)<a*b),那么c也可以找到对应的项,所以分别是(2*c-2)(2*c-1)

    #include <bits/stdc++.h>
    
    using namespace std;
    
    const int N = 1e6 + 5;
    typedef long long LL;
    int q;
    LL x, y;
    int main() {
        cin >> q;
        while (q--) {
            cin >> x >> y;
            if(x>y)swap(x,y);
            if(x==y){
                cout << 2 * x - 2 << endl;
                continue;
            }
            else if(x==y+1){
                cout << 2 * x - 2 << endl;
                continue;
            }
            LL c = sqrt(x * y);
            if (c * c == x * y) c--;
            if(c*(c+1)<x*y){
                cout << 2 * c - 1 << endl;
            }
            else
                cout << 2 * c - 2 << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    Mysql基础3-数据操作语言DML-数据查询语言DQL
    Mysql基础2-数据定义语言DDL
    Mysql基础1-基础语法-字段类型
    php源码建博客5--建库建表-配置文件-错误日志
    PHP基础4--函数-数组
    php源码建博客4--实现MVC结构微型框架
    PHP基础3--文件加载-错误处理
    php源码建博客3--区分平台的MVC结构
    php源码建博客2--实现单入口MVC结构
    php源码建博客1--搭建站点-实现登录页面
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14376639.html
Copyright © 2020-2023  润新知