• Codeforces Round #679


    题目传送门

    A. Finding Sasuke

    n给定了是偶数,两两配对随便怎么搞都行

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i, a, b) for(int i = a; i <= b; i++)
    typedef long long ll;
     
    ll n;
    ll a[110], b[110];
     
    void run(int T) {
        cin >> n;
        rep(i, 1, n) cin >> a[i];
        rep(i, 1, n) if(i <= n / 2) cout << a[n - i + 1] << ' ';
        else cout << -a[n - i + 1] <<  " ";
        cout << endl;
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T = 1;
        cin >> T;
        rep(i, 1, T) run(i);
    }
    View Code

    B. A New Technique

    很显然一个矩阵能确定一个数的其中一维的信息

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i, a, b) for(int i = a; i <= b; i++)
    typedef long long ll;
     
    ll n, m;
    pair<ll, ll> ans[250010];
    ll mp[510][510];
    void run(int T) {
        cin >> n >> m;
        ll f;
        rep(i, 1, n) {
            rep(j, 1, m) {
                cin >> f;
                ans[f].second = j;
            }
        }
        rep(j, 1, m) {
            rep(i, 1, n) {
                cin >> f;
                ans[f].first = i;
            }
        }
        rep(i, 1, n * m) mp[ans[i].first][ans[i].second] = i;
        rep(i, 1, n) {
            rep(j, 1, m) cout << mp[i][j] << ' ';
            cout << '
    ';
        }
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T = 1;
        cin >> T;
        rep(i, 1, T) run(i);
    }
    View Code

    C. Perform Easily

    自闭了,对着个假做法敲了好久

    实际上把$(b[j] - a[i], j)$提出来排个序,就可以双指针筛了,求个包含$1-j$的最短区间

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i, a, b) for(int i = a; i <= b; i++)
    typedef long long ll;
     
    ll a[7];
    ll n, b[100010], ans;
    vector<pair<ll, ll>> v;
    ll vis[100010], cnt, id;
    void run(int T) {
        rep(i, 1, 6) cin >> a[i];
        cin >> n;
        rep(i, 1, n) {
            cin >> b[i];
            rep(j, 1, 6) v.emplace_back(b[i] - a[j], i);
        }
        sort(v.begin(), v.end());
        ans = 1e12;
        for(auto it : v) {
            if(!vis[it.second]) cnt++;
            vis[it.second]++;
            while(cnt == n) {
                ans = min(ans, it.first - v[id].first);
                vis[v[id].second]--;
                if(!vis[v[id++].second]) cnt--;
            }
        }
        cout << ans << endl;
     
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T = 1;
        //cin >> T;
        rep(i, 1, T) run(i);
    }
    View Code

    D. Shurikens

    栈模拟,再用堆check一下

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i, a, b) for(int i = a; i <= b; i++)
    typedef long long ll;
     
    int n;
    stack<int> s;
    char f[200010];
    int a[200010];
    priority_queue<int, vector<int>, greater<int>> q;
    void run(int T) {
        cin >> n;
        rep(i, 1, n * 2) {
            cin >> f[i];
            if(f[i] == '-') cin >> a[i]; 
        }
        rep(i, 1, n * 2) {
            if(f[i] == '+') s.push(i);
            else {
                if(s.empty()) {
                    cout << "NO
    ";
                    return;
                }
                a[s.top()] = a[i];
                s.pop();
            }
        }
        if(!s.empty()) {
            cout << "NO
    ";
            return;
        }
        rep(i, 1, n * 2) {
            if(f[i] == '+') q.push(a[i]);
            else {
                if(q.empty() || q.top() != a[i]) {
                    cout << "NO
    ";
                    return;
                }
                q.pop();
            }
        }
        cout << "YES
    ";
        rep(i, 1, n * 2) if(f[i] == '+') cout << a[i] << ' ';
        cout << '
    ';
     
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T = 1;
        //cin >> T;
        rep(i, 1, T) run(i);
    }
    View Code

    E. Solo mid Oracle

    判断答案为-1的情况,即$a > b * c$

    然后可以推出:消灭最大生命值的时候 一定 在第一次攻击造成的回复之前

    然后对于第i次攻击,造成的伤害为$a$,回复的血量为$b*(i - 1)*d$,找到这个$i$即可

    #include<bits/stdc++.h>
    using namespace std;
    #define rep(i, a, b) for(int i = a; i <= b; i++)
    typedef long long ll;
    
    
    ll a, b, c, d;
    void run(int T) {
        cin >> a >> b >> c >> d;
        if(a > c * b) {
            cout << -1 << '
    ';
            return;
        }
    
        ll tmp = a / (d * b);
        ll ans = (tmp + 1) * a;
        ans -= tmp * (tmp + 1) / 2 * d * b;
        cout << ans << endl;
    }
    int main() {
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
    #endif
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        int T = 1;
        cin >> T;
        rep(i, 1, T) run(i);
    }
    View Code
  • 相关阅读:
    js 对象数组 排序
    sql 时间条件查询
    idea和Pycharm 等系列产品激活激活方法和激活码 100 年
    开源协议简介
    面试题
    VIM|基础命令
    git|基础命令
    VIM|复制
    lua|基础教程
    Printf格式输出详解
  • 原文地址:https://www.cnblogs.com/likunhong/p/13880636.html
Copyright © 2020-2023  润新知