• 2019 CCPC JiangXi Province Contest (江西省赛)


    打得还可以,10题,最后没能做出B有点可惜。

    由于刚刚打完,大部分的题目都是我翻译完之后队友做的,故只贴出代码。

    后面的题目很简单,B和E比较难。


    A:

    solver:zyh、lzh

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 vector<int> li[100001];
     4 long long pTotal[100001];
     5 long long Size[100001];
     6 void dfs(int x, int f, int d, int root) {
     7     Size[x] = 1;
     8     pTotal[root] += d;
     9     for (auto i : li[x]) {
    10         if (i == f) continue;
    11         dfs(i, x, d + 1, root);
    12         Size[x] += Size[i];
    13     }
    14 }
    15 long long Min = 1e18;
    16 void calpTotal(int x, int f, int sum) {
    17     if (x != f) pTotal[x] = pTotal[f] + sum - 2 * Size[x];
    18     Min = min(Min, pTotal[x]);
    19     for (auto i : li[x]) {
    20         if (i == f) continue;
    21         calpTotal(i, x, sum);
    22     }
    23 }
    24 void getInnerSum(int x, int f, long long &innerSum, int sum) {
    25     for (auto i : li[x]) {
    26         if (i == f) continue;
    27         innerSum += Size[i] * (sum - Size[i]);
    28         getInnerSum(i, x, innerSum, sum);
    29     }
    30 }
    31 int main() {
    32     int n;
    33     scanf("%d", &n);
    34     for (int i = 0; i < n - 2; ++i) {
    35         int u, v;
    36         scanf("%d%d", &u, &v);
    37         li[u].push_back(v);
    38         li[v].push_back(u);
    39     }
    40     int root1, root2;
    41     for (int i = 1; i <= n; ++i)
    42         if (!Size[i]) {
    43             root1 = i;
    44             dfs(i, i, 0, i);
    45             break;
    46         }
    47     for (int i = 1; i <= n; ++i)
    48         if (!Size[i]) {
    49             root2 = i;
    50             dfs(i, i, 0, i);
    51             break;
    52         }
    53     Min = 1e18;
    54     calpTotal(root1, root1, Size[root1]);
    55     long long totalA = Min;
    56 
    57     Min = 1e18;
    58     calpTotal(root2, root2, Size[root2]);
    59     long long totalB = Min;
    60 
    61     totalA *= Size[root2];
    62     totalB *= Size[root1];
    63 
    64     long long innerSum1 = 0, innerSum2 = 0;
    65     getInnerSum(root1, root1, innerSum1, Size[root1]);
    66     getInnerSum(root2, root2, innerSum2, Size[root2]);
    67     //cout<<root1<<' '<<root2<<endl;
    68     //cout<<Size[root1]*Size[root2]<<' '<<totalA<<' '<<totalB<<' '<<innerSum1<<' '<<innerSum2<<endl;
    69     printf("%lld
    ", Size[root1]*Size[root2] + totalA + totalB + innerSum1 + innerSum2);
    70 }
    View Code

    B:

    很恶心的概率dp。

    C:

    solver:czq

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define pb emplace_back
     6 #define mp make_pair
     7 #define sot(a,mul) sort(a+1,a+1+mul)
     8 #define eps 1e-8
     9 #define int_inf 0x3f3f3f3f
    10 #define ll_inf 0x7f7f7f7f7f7f7f7f
    11 #define lson (curnumber<<1)
    12 #define rson (curnumber<<1|1)
    13 /* namespace */
    14 using namespace std;
    15 /* header end */
    16 
    17 const int maxn = 1e5 + 10, segLim = 10000;
    18 vector<int>a, mul, huzhi[maxn];
    19 int n, cnt[maxn];
    20 ll ans = 0;
    21 
    22 void init() {
    23     ans = 0; a.clear(); mul.clear();
    24     for (int i = 0; i < maxn; i++) {
    25         cnt[i] = 0; huzhi[i].clear();
    26     }
    27 }
    28 
    29 int main() {
    30     while (~scanf("%d", &n)) {
    31         init();
    32         for (int i = 0; i < n; i++) {
    33             int x; scanf("%d", &x);
    34             cnt[x]++; a.pb(x);
    35         }
    36         sort(a.begin(), a.end());
    37         a.erase(unique(a.begin(), a.end()), a.end());
    38         for (int i = 0; i <= segLim; i++) if (cnt[i] >= 2) mul.pb(i);
    39         for (int i = 1; i <= segLim; i++)
    40             for (int j = 0; j < (int)mul.size(); j++)
    41                 if (__gcd(i, mul[j]) == 1) huzhi[i].pb(mul[j]);
    42         // n^2, enum shang di && xia di
    43         for (int i = 0; i < (int)a.size(); i++) {
    44             for (int j = i + 1; j < (int)a.size(); j++) {
    45                 int gcd = __gcd(a[i], a[j]);
    46                 int curr = 0;
    47                 if ((a[j] - a[i]) % 2 == 0) curr = (a[j] - a[i]) / 2 + 1;
    48                 else curr = (a[j] - a[i] + 1) / 2;
    49                 int number = lower_bound(huzhi[gcd].begin(), huzhi[gcd].end(), curr) - huzhi[gcd].begin();
    50                 ans += (int)huzhi[gcd].size() - number;
    51                 if (gcd == 1) {
    52                     if (a[i] >= curr && cnt[a[i]] == 2) ans--;
    53                     if (a[j] >= curr && cnt[a[j]] == 2) ans--;
    54                 }
    55             }
    56         }
    57         printf("%lld
    ", ans);
    58     }
    59     return 0;
    60 }
    View Code

    D:

    solver:zyh

     1 #include <iostream>
     2 using namespace std;
     3 int a[500001];
     4 int Max[1001];
     5 int bin[1001];
     6 int main() {
     7     int n, c;
     8     scanf("%d%d", &n, &c);
     9     for (int i = 0; i < n; ++i) {
    10         scanf("%d", &a[i]);
    11     }
    12     int ans = 0;
    13     for (int j = 1; j <= c; ++j) {
    14         int cnt = 0;
    15         for (int i = 0; i < n; ++i) {
    16             if (a[i] == j) ++cnt;
    17             else {
    18                 if (Max[a[i]] < cnt) {
    19                     bin[a[i]]++;
    20                     Max[a[i]] = cnt;
    21                 }
    22             }
    23         }
    24         //cout<<"done";
    25         for (int i = 1; i <= c; ++i) {
    26             int s = bin[i] * 2;
    27             if (s == 0) continue;
    28             if (Max[i] < cnt) ++s;
    29             ans = max(ans, s);
    30             bin[i] = 0;
    31             Max[i] = 0;
    32         }
    33         //cout<<"done2";
    34     }
    35     printf("%d
    ", ans);
    36 }
    View Code

    E:

    solver:zyh、lzh

    细节恶心的模拟题。

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <queue>
     4 using namespace std;
     5 
     6 struct item {
     7     int t, x;
     8     item() {}
     9     item(int _t, int _x) {
    10         t = _t;
    11         x = _x;
    12     }
    13     bool operator< (const item &b)const {
    14         return t < b.t;
    15     }
    16 };
    17 struct segment {
    18     int l, r;
    19     segment() {}
    20     segment(int _l, int _r) {
    21         l = _l;
    22         r = _r;
    23     }
    24     bool operator<(const segment &b)const {
    25         if (l != b.l) return l < b.l;
    26         return r < b.r;
    27     }
    28 };
    29 item items[1000001];
    30 int len[1000001];
    31 vector<int> buffers[1000001];
    32 int front[1000001];
    33 vector<segment> overflow;
    34 int main() {
    35     int n, m;
    36     scanf("%d%d", &n, &m);
    37     for (int i = 0; i < n; ++i) {
    38         int t, x;
    39         scanf("%d%d", &t, &x);
    40         items[i] = item(t, x);
    41     }
    42     for (int i = 1; i <= m; ++i) scanf("%d", &len[i]);
    43     sort(items, items + n);
    44     overflow.clear();
    45     for (int i = 0; i < n; ++i) {
    46         buffers[items[i].x].push_back(items[i].t);
    47         //cout<<buffers[items[i].x].size()<<endl;
    48         if (buffers[items[i].x].size() > len[items[i].x]) {
    49             auto t = buffers[items[i].x][front[i]];
    50             front[i]++;
    51             //buffers[items[i].x].pop();
    52             overflow.push_back(segment(t, items[i].t));
    53         }
    54     }
    55     long long ans = 0;
    56     int last = 0;
    57     for (auto i : overflow) {
    58         //cout<<"pp:"<<i.l<<' '<<i.r<<endl;
    59         if (i.l > last) last = i.l + 1;
    60         else last++;
    61         ans += max(0, last - i.r - 1);
    62     }
    63     printf("%lld
    ", ans);
    64 }
    View Code

    F:

    solver:zyh

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 char str[1000];
     4 int main() {
     5     int len;
     6     long long a, v, _i, n;
     7     while (~scanf("%d", &len)) {
     8         scanf("%s", str);
     9         a = v = _i = n = 0;
    10         for (int i = 0; i < len; ++i) {
    11             if (str[i] == 'a') a++;
    12             if (str[i] == 'v') v++;
    13             if (str[i] == 'i') _i++;
    14             if (str[i] == 'n') n++;
    15         }
    16         long long p, q;
    17         //cout<<a<<' '<<v<<' '<<_i<<" "<<n<<endl;
    18         p = a * v * _i * n;
    19         q = len * len * len * len;
    20         long long t = __gcd(p, q);
    21         p /= t; q /= t;
    22         printf("%lld/%lld
    ", p, q);
    23     }
    24 
    25 }
    View Code

    G:

    solver:lzh

    这题我还读错了题意害队友wa了两发……

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef pair<int, int> pii;
     4 #define ff first
     5 #define ss second
     6 
     7 int a[1010], b[1010], vis[3010];
     8 int main() {
     9     int n, m;
    10     while (~scanf("%d%d", &n, &m)) {
    11         for (int i = 1; i <= 1000; i++)vis[i] = 0;
    12         for (int i = 1; i <= n; i++)scanf("%d", &a[i]), vis[a[i]]++;
    13         for (int i = 1; i <= m; i++)scanf("%d", &b[i]);
    14         for (int i = 0; i <= 1010; i++) {
    15             int ok = 1;
    16             for (int j = 1; j <= m; j++)
    17                 if (vis[b[j] + i]) {
    18                     ok = 0;
    19                     break;
    20                 }
    21             if (ok) {
    22                 printf("%d
    ", i);
    23                 break;
    24             }
    25         }
    26     }
    27 }
    View Code

    H:

    solver:zyh、czq

     1 #include <iostream>
     2 using namespace std;
     3 const long long M = 1000000007;
     4 long long qpow(long long x, long long y) {
     5     long long ans = 1;
     6     while (y) {
     7         if (y & 1) ans = (ans * x) % M;
     8         x = x * x % M;
     9         y >>= 1;
    10     }
    11     return ans;
    12 }
    13 int main() {
    14     long long n;
    15     scanf("%lld", &n);
    16     printf("%lld
    ", (n * (n + 1) / 2 % M) * (qpow(n * n, M - 2) % M) % M);
    17 
    18 }
    View Code

    I:

    solver:lzh

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef pair<int, int> pii;
     4 #define ff first
     5 #define ss second
     6 
     7 int main() {
     8     int n;
     9     while (~scanf("%d", &n)) {
    10         double ans = 0;
    11         for (int i = 1; i <= n; i++) {
    12             char s[20]; scanf("%s", s + 1);
    13             int len = strlen(s + 1);
    14             if (s[len] >= '5')ans += 0.001 * ('9' - s[len] + 1);
    15             else ans -= 0.001 * (s[len] - '0');
    16         }
    17         printf("%.3lf
    ", ans);
    18     }
    19 }
    View Code

    J:

    solver:zyh、lzh

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 typedef pair<ll, ll> pii;
     5 #define ff first
     6 #define ss second
     7 
     8 ll lcm(ll a, ll b) {
     9     return a / __gcd(a, b) * b;
    10 }
    11 
    12 ll a[1010];
    13 int main() {
    14     int n; ll m;
    15     while (~scanf("%d%lld", &n, &m)) {
    16         for (int i = 1; i <= n; i++)scanf("%lld", &a[i]);
    17         pii cur = make_pair(1, a[1]);
    18         for (int i = 2; i <= n; i++) {
    19             ll x = lcm(cur.ss, a[i]);
    20             cur.ff = cur.ff * (x / cur.ss) + x / a[i];
    21             cur.ss = x;
    22             ll g = __gcd(cur.ff, cur.ss);
    23             cur.ff /= g, cur.ss /= g;
    24         }
    25         if (m % cur.ff) {
    26             printf("No
    "); continue;
    27         }
    28         ll x = m / cur.ff * cur.ss;
    29         ll lcmm = 1;
    30         for (int i = 1; i <= n; i++)lcmm = lcm(lcmm, a[i]);
    31         if (x % lcmm) {
    32             printf("No
    "); continue;
    33         } else {
    34             printf("Yes
    ");
    35             printf("%lld", x / a[1]);
    36             for (int i = 2; i <= n; i++)printf(" %lld", x / a[i]);
    37             printf("
    ");
    38         }
    39     }
    40 }
    View Code

    K:

    solver:zyh

    1 #include <iostream>
    2 using namespace std;
    3 int main() {
    4     int a, b;
    5     cin >> a >> b;
    6     int x = a + b;
    7     int y = a - b;
    8     cout << x *y / 4 << endl;
    9 }
    View Code
  • 相关阅读:
    Linux 下没有 my.cnf 文件的解决方式,完全是我自己整的,好多教程都是瞎扯的 (zhuan)
    Virtualbox虚拟机安装CentOS6.5图文详细教程(zhuan)
    virtualbox中centos系统配置nat+host only上网(zhuan)
    VirtualBox的网络配置,Host Only+NAT方式 (zhuan)
    Linux上安装Mysql后除了本机其他机器不能访问的问题(zhuan)
    VirtualBox没有64位选项,无法安装64位的解决方法(zhuan)
    CentOS查看内核版本,位数,版本号 (zhuan)
    datagrid实现单行的选择、取消
    datagrid实现行的上移和下移
    Excel 、数据库 一言不合就转换 (zhuan)
  • 原文地址:https://www.cnblogs.com/JHSeng/p/12180941.html
Copyright © 2020-2023  润新知