2020 Multi-University Training Contest 2(待补

2020 Multi-University Training Contest 2

1001 Total Eclipse

  • 思路:最后删除的是最大的点,则按从大到小排序,每次加入点,先判断其相邻点是否已加入,有就合并,每次的贡献是已加入点个数*相邻点权的差值

  • 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 = 1e5 + 10;

int t, n, m;
int w[N], pos[N], fa[N];
bool vis[N];
ll tot, ans;
vector<int> g[N << 2];

inline int find(int x){
    if (x == fa[x])
        return x;
    return fa[x] = find(fa[x]);
}

inline bool cmp(int a, int b){
    return w[a] > w[b];
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t -- ){
        tot = 0, ans = 0;
        memset(vis, false, sizeof(vis));
        cin >> n >> m;
        for (int i = 1; i <= n; i ++ ){
            cin >> w[i];
            pos[i] = fa[i] = i;
            g[i].clear();
        }
        sort(pos + 1, pos + n + 1, cmp);
        pos[n + 1] = 0;
        for (int i = 1; i <= m; i ++ ){
            int u, v;
            cin >> u >> v;
            g[v].push_back(u);
            g[u].push_back(v);
        }
        for (int i = 1; i <= n; i ++ ){
            tot ++ ;
            vis[pos[i]] = true;
            for (auto v: g[pos[i]]){
                if (!vis[v])
                    continue;
                int v_ = find(v), u_ = find(pos[i]);
                if (v_ != u_){
                    fa[u_] = v_;
                    tot -- ;
                }
            }
            ans += tot * (w[pos[i]] - w[pos[i + 1]]);
        }
        cout << ans << "\n";
    }
    return 0;
}

1006 The Oculus

  • 思路:用ull 暴力即可

  • 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 = 2e6 + 10;

int t, n, x;
ull s1, s2, s3;
ull f[N];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    f[1] = 1, f[2] = 2;
    for (int i = 3; i < N; i ++ )
        f[i] = f[i - 1] + f[i - 2];
    cin >> t;
    while (t -- ){
        s1 = s2 = s3 = 0;
        cin >> n;
        for (int i = 1; i <= n; i ++ ){
            cin >> x;
            s1 += x * f[i];
        }
        cin >> n;
        for (int i = 1; i <= n; i ++ ){
            cin >> x;
            s2 += x * f[i];
        }
        cin >> n;
        for (int i = 1; i <= n; i ++ ){
            cin >> x;
            s3 += x * f[i];
        }
        for (int i = 1; i <= n; i ++ ){
            if (s1 * s2 == s3 + f[i]){
                cout << i << "\n";
                break;
            }
        }
    }
    return 0;
}

1010 Lead of Wisdom

  • 思路:暴力dfs即可

  • 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 = 60;

int T, n, k, t, tot;
ll a, b, c, d, ans;

struct node{
    ll a, b, c, d;
}now;

map<int, int> mp;
vector<node> vec[N];

inline void dfs(int t, ll a, ll b, ll c, ll d){
    if (t > tot){
        ans = max(ans, a * b * c * d);
        return ;
    }
    for (auto v: vec[t])
        dfs(t + 1, a + v.a, b + v.b, c + v.c, d + v.d);
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while (T -- ){
        tot = 0, ans = 0;
        mp.clear();
        for (int i = 0; i < N; i ++ )
            vec[i].clear();
        cin >> n >> k;
        for (int i = 1; i <= n; i ++ ){
            cin >> t >> a >> b >> c >> d;
            if (!mp[t])
                mp[t] = ++ tot ;
            vec[mp[t]].push_back({a, b, c, d});
        }
        dfs(1, 100, 100, 100, 100);
        cout << ans << "\n";
    }
    return 0;
}
posted @ 2020-07-27 21:26  Misuchii  阅读(165)  评论(0编辑  收藏  举报