码迷,mamicode.com
首页 > 其他好文 > 详细

2020 年 “游族杯” 全国高校程序设计网络挑战赛

时间:2020-05-24 00:33:08      阅读:720      评论:0      收藏:0      [点我收藏+]

标签:inf   目录   std   pac   include   攻击   amp   +=   int   


传送门

Solved A B C D E F G H I
5 / 9 O - ? ? - O - - O
  • O 在比赛中通过
  • ? 赛后通过
  • ! 尝试了但是失败了
  • - 没有尝试

A. Amateur Chess Players

简单博弈,显然每次每个人只会选择一个。

Code
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/23 13:16:27
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ‘ ‘; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ‘ ‘; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

void run() {
    int n, m;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s; cin >> s;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        string s; cin >> s;
    }
    if (n <= m) cout << "Quber CC" << ‘\n‘;
    else cout << "Cuber QQ" << ‘\n‘;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

C. Coronavirus Battle

题意:
随机在三维空间中给定\(n\)个点,现在有病毒进行攻击,每次病毒会攻击当前没有受保护的点。
定义结点\(i\)保护结点\(j\)为:

  • \(x_i\leq x_j,y_i\leq y_j,z_i\leq z_j\)且两点不重合。

问病毒攻击几轮能消灭所有的点,并且输出每个点存活的轮数。

思路:
因为是随机数据,所以我们可以直接通过模拟上述过程来做。
模拟的思想就是我们对于每一轮攻击,选出一个最小的点,然后找到所有不能保护的点,他们都会在这一轮攻击中被消灭;然后进行下一轮攻击。
具体实现我们可以直接枚举或者用树状数组维护\(z\)的最小值都可。反正数据随机可以不用管复杂度= =
还有一种复杂度比较稳定的做法就是cdq分治,用cdq分治维护每个结点的拓扑序即可。注意一下这种写法我们要按照拓扑序进行转移,也就是说在cdq分治中,先处理左边的,然后处理左边对右边的影响,最后再处理右边。这样能够保证拓扑序从小到大转移。
详见代码:

Code
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/23 14:57:55
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ‘ ‘; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ‘ ‘; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

unsigned long long k1, k2;
unsigned long long CoronavirusBeats() {
    unsigned long long k3 = k1, k4 = k2;
    k1 = k4;
    k3 ^= k3 << 23;
    k2 = k3 ^ k4 ^ (k3 >> 17) ^ (k4 >> 26);
    return k2 + k4;
}
unsigned long long x[N], y[N], z[N];

struct Point {
    unsigned long long x, y, z;
    int id;   
}a[N], b[N];

int n;
int ans[N];

void Hash(unsigned long long* a) {
    sort(a + 1, a + n + 1);
    a[0] = unique(a + 1, a + n + 1) - a - 1;
}

int find(unsigned long long* a, unsigned long long x) {
    return lower_bound(a + 1, a + a[0] + 1, x) - a;
}

int c[N];

int lowbit(int x) {
    return x & (-x);
}
void del(int x) {
    for (int i = x; i < N; i += lowbit(i)) c[i] = 0;
}
void add(int x, int v) {
    for(int i = x; i < N; i += lowbit(i)) c[i] = max(c[i], v);
}
int query(int x) {
    int ans = 0;
    for(int i = x; i; i -= lowbit(i)) ans = max(ans, c[i]);
    return ans;
}
void cdq(int l, int r) {
    if(l == r) return ;
    int mid = (l + r) >> 1;
    cdq(l, mid);
    sort(a + l, a + mid + 1, [&](Point A, Point B) {
        return A.y < B.y;
    });
    sort(a + mid + 1, a + r + 1, [&](Point A, Point B) {
        return A.y < B.y;
    });
    int t1 = l, t2 = mid + 1;
    for(int i = l; i <= r; i++) {
        if((t1 <= mid && a[t1].y <= a[t2].y) || t2 > r) {
            add(a[t1].z, ans[a[t1].id]);
            b[i] = a[t1++];
        } else {
            ans[a[t2].id] = max(ans[a[t2].id], query(a[t2].z) + 1);
            b[i] = a[t2++];
        }
    }
    for(int i = l; i <= mid; i++) del(a[i].z);
    sort(a + mid + 1, a + r + 1, [&](Point A, Point B) {
        return A.x < B.x;
    });
    cdq(mid + 1, r);
}

void run() {
    cin >> n >> k1 >> k2;
    for (int i = 1; i <= n; ++i) {
        x[i] = CoronavirusBeats();
        y[i] = CoronavirusBeats();
        z[i] = CoronavirusBeats();
        a[i] = Point{x[i], y[i], z[i], i};
    }
    Hash(x), Hash(y), Hash(z);
    for (int i = 1; i <= n; i++) {
        a[i].x = find(x, a[i].x);
        a[i].y = find(y, a[i].y);
        a[i].z = find(z, a[i].z);
    }   
    sort(a + 1, a + n + 1, [&](Point A, Point B) {
        return A.x < B.x;
    });
    for (int i = 1; i <= n; i++) {
        ans[i] = 1;
    }
    cdq(1, n);
    int res = 0;
    for (int i = 1; i <= n; i++) {
        res = max(res, ans[i]);
        --ans[i];
    }
    cout << res << ‘\n‘;
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " \n"[i == n];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

D. Decay of Signals

题意:
给定一颗带点权的树,定义一条路径的价值为\(\displaystyle \frac{a_{p_1}\cdot a_{p_2}\cdots a_{p_m}}{m}\)
现在问路径价值的最小值为多少,输出\("x/y"\)

思路:
分几种清空考虑:

  • 存在\(a_i=0\),那么答案显然;
  • 所有\(a_i\geq 2\),答案即为\(min\{a_i\}\)
  • 找到最长连续的\(1\),设长度为\(m\),那么答案为\(\frac{1}{m}\)。考虑最终答案为\(111x111...\)这样的形式,我们容易发现当\(x=2\)并且左右两边都有\(m\)\(1\)时会出现更优解。所以找一下这种情况就行。

思路就是上面这样,具体的证明应该也比较好证,就拿第三种情况证明一下:
首先答案为\(\frac{1}{m}\),假设现在有\(t\)段连续的\(1\)长度为\(m\),那么答案为\(\displaystyle\frac{b_1\cdots b_{t-1}}{tm+t-1}\),因为\(b_i\geq 2\),我们就取\(b_i=2\),将其与\(\frac{1}{m}\)做差得\(\displaystyle m(2^{t-1}-t)-t+1\)。容易发现当\(t=2\)时,差为负数;当\(t>2\)时,差为非负数;若\(b_i\geq 3\),值为非负数。也就是说只有我们上述所说情况会出现最优解。
证明大概就是这个样子,可能细节会有点问题。。
思路是这样,代码写起来还是挺麻烦的,需要换下根。
详见代码:

Code
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/23 20:42:25
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ‘ ‘; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ‘ ‘; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e6 + 5;

int n;
int a[N];
struct Edge {
    int u, v;
}e[N];

vector <int> G[N];
bool vis[N];
int f[N][2], g[N];

void run() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        e[i] = Edge {u, v};
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    pii ans(INF, INF);
    for (int i = 1; i <= n; i++) {
        if (a[i] == 0) {
            cout << "0/1" << ‘\n‘;
            return;
        }
        ans = min(ans, MP(a[i], 1));
    }
    if (ans.fi > 1) {
        cout << ans.fi << ‘/‘ << ans.se << ‘\n‘;
        return;
    }
    for (int i = 1; i < n; i++) {
        int u = e[i].u, v = e[i].v;
        if (a[u] == 1 && a[v] == 1) {
            G[u].push_back(v);
            G[v].push_back(u);
        }
    }
    
    int m = 0, rt;
    function <void(int, int, int)> dfs;
    dfs = [&](int u, int fa, int d) -> void {
        if (d > m) {
            m = d, rt = u;   
        }
        vis[u] = 1;
        for (auto v : G[u]) if (v != fa) {
            dfs(v, u, d + 1);
        }
    };
    
    function <void(int, int)> dfs2;
    dfs2 = [&](int u, int fa) -> void {
        f[u][0] = 1, f[u][1] = -1;
        for (auto v : G[u]) if (v != fa) {
            dfs2(v, u);
            if (f[v][0] + 1 > f[u][0]) {
                f[u][1] = f[u][0];
                f[u][0] = f[v][0] + 1;
            } else if(f[v][0] + 1 > f[u][1]) {
                f[u][1] = f[v][0] + 1;   
            }
        }       
    };
    
    function <void(int, int, int)> dfs3;
    dfs3 = [&](int u, int fa, int h) -> void {
        for (auto v : G[u]) if (v != fa) {
            g[v] = f[v][0];
            if (f[v][0] + 1 == f[u][0]) {
                g[v] = max(g[v], max(h, f[u][1]) + 1);
                dfs3(v, u, max(h, f[u][1]) + 1);
            } else {
                g[v] = max(g[v], max(h, f[u][0]) + 1);
                dfs3(v, u, max(h, f[u][0]) + 1);
            }
        }
    };
    
    int MAX = 0;
    for (int i = 1; i <= n; i++) if (a[i] == 1 && !vis[i]) {
        rt = i, m = 0;
        dfs(rt, 0, 1), dfs(rt, 0, 1);
        MAX = max(m, MAX);
        dfs2(i, 0);
        g[i] = f[i][0];
        dfs3(i, 0, 0);
    }
    ans = MP(1, MAX);
    vector <int> d(n + 1);
    for (int i = 1; i < n; i++) {
        int u = e[i].u, v = e[i].v;
        if (a[u] > a[v]) swap(u, v);
        if (a[u] == 1 && a[v] == 2) {
            if (g[u] == MAX) ++d[v];
            if (d[v] >= 2) {
                ans = MP(2, 2 * MAX + 1);
                break;
            }
        }
    }
    cout << ans.fi << ‘/‘ << ans.se << ‘\n‘;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

F. Find / -type f -or -type d

排序过后判断是否为某一个的前缀就行,我的时间复杂度貌似有点炸,但依旧跑得飞快。
正解的话就直接上字典树吧。

Code

/*
 * Author:  heyuhhh
 * Created Time:  2020/5/23 13:35:27
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ‘ ‘; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ‘ ‘; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e6 + 5;

void run() {
    int n; cin >> n;
    vector <string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    sort(all(s));
    int ans = 0;
    auto chk = [&] (string& str) {
        int len = str.length();
        if (len > 3 && str.substr(len - 4) == ".eoj") return 1;
        return 0;        
    };
    for (int i = 0, j; i < n; i++) {
        if (i == n - 1) {
            ans += chk(s[i]);
        } else {
            int l1 = s[i].length(), l2 = s[i + 1].length();
            if (l1 > l2) {
                ans += chk(s[i]);
            } else if (s[i + 1].substr(0, l1) != s[i]) {
                ans += chk(s[i]);
            }
        }
    }
    cout << ans << ‘\n‘;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

I. Idiotic Suffix Array

随便构造一下就行。

Code
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/23 13:23:08
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ‘ ‘; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ‘ ‘; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

void run() {
    int n, k; cin >> n >> k;
    string ans = "";
    for (int i = 1; i < k; i++) ans += "a";
    for (int i = 1; i <= n - k; i++) ans += "c";
    ans += "b";
    reverse(all(ans));
    cout << ans << ‘\n‘;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

2020 年 “游族杯” 全国高校程序设计网络挑战赛

标签:inf   目录   std   pac   include   攻击   amp   +=   int   

原文地址:https://www.cnblogs.com/heyuhhh/p/12945175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!