zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 144

    AtCoder Beginner Contest 144

    A - 9x9

    • 思路:水题

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    int a, b;
    
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> a >> b;
        if (a <= 9 && b <= 9)
            cout << a * b << "
    ";
        else
            cout << "-1
    ";
        return 0;
    }
    

    B - 81

    • 思路:水题

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    int n;
    
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        bool flag = false;
        for (int a = 1; a <= 9; a ++ ){
            for (int b = 1; b <= 9; b ++ ){
                if (a * b == n){
                    flag = true;
                    break;
                }
            }
            if (flag)
                break;
        }
        if (flag)
            cout << "Yes
    ";
        else
            cout << "No
    ";
        return 0;
    }
    

    C - Walk on Multiplication Table

    • 思路:暴力即可

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    ll n, tmp, ans;
    
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        tmp = sqrt(n);
        for (ll i = tmp; i >= 1; i -- ){
            if (n % i == 0){
                ans = i + n / i - 2;
                break;
            }
        }
        cout << ans << "
    ";
        return 0;
    }
    

    D - Water Bottle

    • 思路:两种情况比较一下即可

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    const double pi = acos(-1);
    
    double a, b, x, s, h, ans;
    
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> a >> b >> x;
        s = x / a;
        if (s >= a * b / 2){
            h = (a * b - s) * 2 / a;
            ans = 180 * atan2(h, a) / pi;
        }
        else{
            h = s * 2 / b;
            ans = 180 * atan2(b, h) / pi;
        }
        printf("%.8lf
    ", ans);
        return 0;
    }
    

    E - Gluttony

    • 思路:二分 上界为最大的最小(a)(*)最大(f)

    • AC代码


    #include <algorithm>
    #include <iomanip>
    #include <iostream>
    #include <map>
    #include <math.h>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdio.h>
    #include <string.h>
    #include <string>
    typedef long long ll;
    typedef unsigned long long ull;
    using namespace std;
    
    ll mult_mod(ll x, ll y, ll mod){
        return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
    }
    
    ll pow_mod(ll a, ll b, ll p){
        ll res = 1;
        while (b){
            if (b & 1)
                res = mult_mod(res, a, p);
            a = mult_mod(a, a, p);
            b >>= 1;
        }
        return res % p;
    }
    
    ll gcd(ll a, ll b){
        return b ? gcd(b, a % b) : a;
    }
    
    const int N = 2e5 + 10;
    
    ll n, k, x, l, r, mid, tmp;
    vector<ll> a, f;
    
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n >> k;
        for (int i = 1; i <= n; i ++ ){
            cin >> x;
            a.push_back(x);
        }
        for (int i = 1; i <= n; i ++ ){
            cin >> x;
            f.push_back(x);
        }
        sort(a.begin(), a.end());
        sort(f.rbegin(), f.rend());
        for (int i = 0; i < n; i ++ )
            r = max(r, a[i] * f[i]);
        while (l < r){
            mid = (l + r) >> 1;
            tmp = 0;
            for (int i = 0; i < n; i ++ )
                tmp += max(0ll, a[i] - mid / f[i]);
            if (tmp <= k)
                r = mid;
            else
                l = mid + 1;
        }
        cout << l << "
    ";
        return 0;
    }
    
  • 相关阅读:
    实现带有头结点的链表
    数据结构之链式线性表
    HDU 1010 dfs+奇偶剪枝
    数据结构之顺序线性表
    POJ 1753 dfs+枚举
    HDU 4277 dfs+set去重
    平衡二叉树
    线性素数筛+欧拉线性筛(证明)
    dp--2019南昌网络赛B-Match Stick Game
    线段树+单调栈+前缀和--2019icpc南昌网络赛I
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11762565.html
Copyright © 2011-2022 走看看