zoukankan      html  css  js  c++  java
  • Codeforces Round #587 (Div. 3)

    Codeforces Round #587 (Div. 3)

    A. Prefixes

    • 思路:水题

    • 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, cnt;
    string s;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n >> s;
        for (int i = 0; i < n; i += 2){
            if (s[i] == s[i + 1]){
                cnt ++ ;
                if (s[i] == 'b')
                    s[i] = 'a';
                else
                    s[i] = 'b';
            }
        }
        cout << cnt << "
    " << s << "
    ";
        return 0;
    }
    

    B. Shooting

    • 思路:贪心 写个struct 从大到小排序计算

    • 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 = 1010;
    
    struct node{
        int a, id;
    }a[N];
    
    inline bool cmp(const node &a, const node &b){
        return a.a > b.a;
    }
    
    int n, ans;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        for (int i = 1; i <= n; i ++ ){
            cin >> a[i].a;
            a[i].id = i;
        }
        sort(a + 1, a + n + 1, cmp);
        for (int i = 1; i <= n; i ++ )
            ans += a[i].a * (i - 1) + 1;
        cout << ans << "
    ";
        for (int i = 1; i < n; i ++ )
            cout << a[i].id << " ";
        cout << a[n].id << "
    ";
        return 0;
    }
    

    C. White Sheet

    • 思路:把所有不可能的情况枚举出来

    • 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 x1, y1_, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> x1 >> y1_ >> x2 >> y2 >> x3 >> y3 >> x4 >> y4 >> x5 >> y5 >> x6 >> y6;
        if ((x1 >= x3 && x2 <= x4 && y1_ >= y3 && y2 <= y4) || (x1 >= x5 && x2 <= x6 && y1_ >= y5 && y2 <= y6))
            cout << "NO
    ";
        else if ((y1_ >= y3 && y2 <= y4 && y1_ >= y5 && y2 <= y6) && (x1 >= x3 && x2 <= x6 && x4 >= x5 || x1 >= x5 && x2 <= x4 && x3 <= x6))
            cout << "NO
    ";
        else if ((x1 >= x3 && x2 <= x4 && x1 >= x5 && x2 <= x6) && (y1_ >= y3 && y2 <= y6 && y4 >= y5 || y1_ >= y5 && y2 <= y4 && y3 <= y6))
            cout << "NO
    ";
        else
            cout << "YES
    ";
        return 0;
    }
    

    D. Swords

    • 思路:排序后求最大的和其他每一项的差之和与gcd 答案为(sum / gcd)(gcd)

    • 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;
    
    int n;
    ll sum, gcd_;
    ll a[N];
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> n;
        for (int i = 1; i <= n; i ++ )
            cin >> a[i];
        sort(a + 1, a + n + 1);
        for (int i = 1; i < n; i ++ ){
            sum += a[n] - a[i];
            gcd_ = gcd(gcd_, a[n] - a[i]);
        }
        cout << sum / gcd_ << " " << gcd_ << "
    ";
        return 0;
    }
    

    E1. Numerical Sequence (easy version)

    • 思路:只会easy version 暴力搞

    • 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 q, tot;
    ll k;
    string s;
    
    int main(){
    #ifndef ONLINE_JUDGE
        freopen("my_in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        cin >> q;
        while (q -- ){
            tot = 1;
            s.clear();
            cin >> k;
            while (s.length() < k){
                k -= s.length();
                s += to_string(tot ++ );
            }
            cout << s[k - 1] << "
    ";
        }
        return 0;
    }
    
  • 相关阅读:
    Python机器学习(五十三)SciPy 特殊函数
    Python机器学习(五十二)SciPy 基础功能
    Ofbiz项目学习——阶段性小结——服务返回结果
    Ofbiz项目学习——阶段性小结——视图
    Java-Eclipse-findbugs-sonar学习
    高性能MySQL
    Excel——读取文件后——组装成待插入数据库数据——实体映射模式
    Excel——读取——导出目录
    导入Excel——解析Excel——优化
    导入Excel——解析Excel
  • 原文地址:https://www.cnblogs.com/Misuchii/p/11801528.html
Copyright © 2011-2022 走看看