Codeforces Round #679 (Div. 2, based on Technocup 2021 Elimination Round 1)

考场上只做出来四道,第二天一早就写出来了E,蛮绝望的。

A Finding Sasuke

水构造

#include <cstdio>
#include <algorithm>
typedef long long ll;
int T,n;
int a[110];

template <typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
int main(){
    read(T);
    while(T--){
        read(n);
        for(int i = 1;i <= n; i++) read(a[i]);
        for(int i = 2;i <= n; i += 2)
            printf("%d %d ",-a[i],a[i - 1]);
        printf("\n");
    }
    return 0;
}

 

B A New Technique

#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
typedef long long ll;
const int M = 510;
int T,n,m;
int a[M][M];

template <typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
std::map <int,int> mp;
int main(){
    read(T);
    while(T--){
        mp.clear();
        read(n); read(m);
        for(int i = 1;i <= n; i++)
            for(int j = 1;j <= m; j++){
                read(a[i][j]);
                if(j == 1) mp[a[i][j]] = i;
            }
        for(int i = 1,tmp;i <= m; i++)
            for(int j = 1;j <= n; j++){
                read(tmp);
                if(mp[tmp] != 0){
                    for(int k = 1;k <= m; k++)
                        printf("%d ",a[mp[tmp]][k]);
                    printf("\n");
                }
            }
    }
    return 0;
}

 

C Perform Easily

思维题

#include <cstdio>
#include <algorithm>
#include <vector>
const int M = 100010, inf = 0x3f3f3f3f;
int a[7], n;
int b[M];
int ans = inf;
int maxx;

std::vector<std::pair<int, std::pair<int, int> > > v;
template <typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
inline bool cmp(int x,int y){
    return x > y;
}
int main(){
    for(int i = 1;i <= 6; i++) read(a[i]);
    read(n);
    for(int i = 1;i <= n; i++) read(b[i]);
    std::sort(a + 1,a + 1 + 6,cmp);
    for(int i = 1;i <= n; i++){
        for(int j = 1; j <= 6; j++) v.push_back(std::make_pair(b[i] - a[j],std::make_pair(i, j)));
        maxx = std::max(maxx,b[i] - a[1]);
    }
    std::sort(v.begin(),v.end());
    bool flag;
    for(int i = 0,l,r;i < int(v.size()); ){
        l = i; r = i;
        while(r < int(v.size()) - 1 && v[r + 1].first == v[r].first) r++;
        flag = 0;
        ans = std::min(ans,maxx - v[i].first);
        for(int j = l; j <= r; j++){
            if(v[j].second.second == 6){
                flag = 1; break;
            }
            maxx = std::max(maxx,b[v[j].second.first] - a[v[j].second.second + 1]);
        }
        if(flag) break;
        i = r + 1;
    }
    printf("%d\n",ans);
    return 0;
}

 

D Shurikens

大模拟

#include <cstdio>
#include <algorithm>
const int M = 1e5 + 19;
int n;

namespace tr{
    int tr[M];
    void update(int x, int k){
        for(; x <= n; x += x & -x)
            tr[x] = std::max(tr[x], k);
    }
    int query(int x){
        int res = 0;
        for(; x; x -= x & -x)
            res = std::max(res, tr[x]);
        return res;
    }
}//树状数组
int b[M], f[M];
int find(int node){
    return node == f[node] ? node : f[node] = find(f[node]);
}
template <typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
int cnt = 0, x;
int main(){
    read(n);
    for(int i = 1; i <= n + 1; ++i) f[i] = i;
    for(int i = 1; i <= 2 * n; ++i){
        char ch = getchar();
        while(ch != '+' && ch != '-') ch = getchar();
        if(ch == '+') ++cnt;
        else{
            read(x);
            int pos = find(tr::query(n - x + 1) + 1);
            if(pos <= cnt) b[pos] = x, tr::update(n - x + 1, cnt), f[find(pos)] = find(pos + 1);
            else return printf("NO\n"), 0;
        }
    }
    printf("YES\n");
    for(int i = 1; i <= n; i++) printf("%d ", b[i]);
    return 0;
}

 

E Solo mid Oracle

有一个显而易见的结论: 造成a伤害之后,如果怪回了超过a的血量,那么这次就算白打了。

因此只需要在回满血之前尽可能地输出,就一定是最优的。

具体见代码。

#include <cstdio>
#include <algorithm>
typedef long long ll;
int T,a,b,c,d;

template <typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}
int main(){
    read(T);
    while(T--){
        read(a); read(b); read(c); read(d);
        if(a > 1ll * b * c){
            printf("-1\n"); continue;
        }
        if(d >= c){
            printf("%d\n",a); continue;
        }
        int k = a / (1ll * b * d);
        printf("%lld\n",(1ll * a * (k + 1) - 1ll * k * (k + 1) * b * d / 2));
    }
    return 0;
}

 

posted @ 2020-10-26 11:32  Tinder  阅读(136)  评论(1)    收藏  举报