zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    BZOJ3403: [Usaco2009 Open]Cow Line 直线上的牛
    lintcode入门篇三
    lintcode入门篇二
    lintcode入门篇一
    matplotlib
    Pandas
    Numpy
    缓存
    Django性能优化的几种方法
    python总结十一
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14376639.html
Copyright © 2011-2022 走看看