• 2019-2020 ACM-ICPC Latin American Regional Programming Contest


    开学前最后一场训练了,努力搞了个8题,还算可以。就是这场题没多少我能做的,只切了两道题。

    题目链接:https://codeforces.com/gym/102428


    D:

    solver:czq

    题意就是二维平面上有n颗恒星,每颗恒星有一个固定亮度。问:是否存在一条直线,从平面的一端扫到另一端,满足:对于任意两颗恒星S和T,如果S亮度大于T,那么S一定在T之前或者跟T一起同时被直线扫到。只需输出Y或N。

    构造一下Y和N的例子你就会发现,对于所有亮度不同的恒星,从亮度高的恒星指向亮度低的恒星,这样我们就得到若干条向量。若答案为Y,那么必然存在一对向量,平行且方向相反,而且如果我们把所有的向量极角排序,这对平行的向量位置相邻。

     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 eps 1e-8
     8 #define lson (curpos<<1)
     9 #define rson (curpos<<1|1)
    10 /* namespace */
    11 using namespace std;
    12 /* header end */
    13 
    14 const double pi = acos(-1);
    15 const int maxn = 2020;
    16 
    17 struct Star {
    18     int x, y, b;
    19 } star[maxn];
    20 vector<double>k;
    21 int n;
    22 
    23 double getRad(int x, int y) {
    24     if (!y) return x > 0 ? 0 : pi;
    25     if (!x) return y > 0 ? pi / 2 : -pi / 2;
    26     double ans = atan(double(y) / x);
    27     return x > 0 ? ans : ans + pi;
    28 }
    29 
    30 bool check() {
    31     if (k.size() < 2) return true;
    32     double last = k.back() - pi * 2;
    33     for (auto x : k) {
    34         if (pi - x + last <= eps) return true;
    35         last = x;
    36     }
    37     return false;
    38 }
    39 
    40 int main() {
    41     scanf("%d", &n);
    42     for (int i = 0; i < n; i++) {
    43         scanf("%d%d%d", &star[i].x, &star[i].y, &star[i].b);
    44         for (int j = 0; j < i; j++) {
    45             if (star[i].b > star[j].b) k.pb(getRad(star[i].x - star[j].x, star[i].y - star[j].y));
    46             else if (star[i].b < star[j].b) k.pb(getRad(star[j].x - star[i].x, star[j].y - star[i].y));
    47         }
    48     }
    49     sort(k.begin(), k.end());
    50     if (check()) puts("Y"); else puts("N");
    51     return 0;
    52 }
    View Code

    E:

    solver:lzh

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define ff first
     4 #define ss second
     5 typedef long long ll;
     6 typedef pair<int, int> pii;
     7 
     8 char s[200010];
     9 int a[200010];
    10 int main() {
    11     int m;
    12     scanf("%s%d", s + 1, &m);
    13     int n = strlen(s + 1);
    14     for (int i = 1; i <= n; i++)
    15         s[i + n] = s[i];
    16     for (int i = 1; i <= 2 * n; i++)
    17         if (s[i] == 'E')
    18             a[++a[0]] = i;
    19     if (!a[0]) {
    20         printf("0
    ");
    21         return 0;
    22     }
    23     int last = 1;
    24     ll ans = 0;
    25     for (int i = 1; i <= n; i++) {
    26         if (a[last] < i && last <= a[0])
    27             last++;
    28         if (last > a[0])
    29             break;
    30         ans += max(0, i + m - a[last]);
    31     }
    32     printf("%lld
    ", ans);
    33 }
    View Code

    F:

    solver:lzh、zyh

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define ff first
     4 #define ss second
     5 typedef long long ll;
     6 typedef pair<int, int> pii;
     7 
     8 ll a[5010][5010];
     9 const int mod = 1e9 + 7;
    10 int main() {
    11     int n, m;
    12     scanf("%d%d", &n, &m);
    13     if (n == 1)
    14         printf("1
    ");
    15     else if (n == 2)
    16         printf("%d
    ", m - 1);
    17     else {
    18         for (int i = 1; i <= 5000; i++)
    19             a[1][i] = 1, a[2][i] = i - 1;
    20         for (int i = 3; i <= n; i++)
    21             for (int j = i; j <= m; j++) {
    22                 int tmp = j - 1;
    23                 while (tmp > 0) {
    24                     a[i][j] = (a[i][j] + a[i - 1][tmp] * 2 % mod - a[i - 2][tmp - 1] + mod) % mod;
    25                     tmp -= i;
    26                 }
    27             }
    28         printf("%lld
    ", a[n][m]);
    29     }
    30 }
    View Code

    G:

    solver:zyh、czq

     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <vector>
     5 using namespace std;
     6 #define STRMAXLEN 500000
     7 struct SAM {
     8     struct node {
     9         int parent, next[26], len;
    10         int cnt;
    11     };
    12     node tr[STRMAXLEN];
    13     int sz[STRMAXLEN];
    14     int rnk[STRMAXLEN];
    15     int last = 0;
    16     int num = 0;
    17     void init() {
    18         last = 0;
    19         num = 0;
    20         tr[0].parent = -1;
    21     }
    22     void add(char ch) {
    23         int p = last;
    24         int t = ch - 'A';
    25         int now = ++num;
    26         tr[now].len = tr[last].len + 1;
    27         tr[now].cnt = 1;
    28         while (p != -1 && tr[p].next[t] == 0) {
    29             tr[p].next[t] = now;
    30             p = tr[p].parent;
    31         }
    32         if (p != -1) {
    33             int q = tr[p].next[t];
    34             if (tr[p].len + 1 == tr[q].len) {
    35                 tr[num].parent = q;
    36             } else {
    37                 tr[++num].parent = tr[q].parent;
    38                 memcpy(tr[num].next, tr[q].next, sizeof(tr[num].next));
    39                 tr[num].len = tr[p].len + 1;
    40                 while (p != -1 && tr[p].next[t] == q) {
    41                     tr[p].next[t] = num;
    42                     p = tr[p].parent;
    43                 }
    44                 tr[now].parent = tr[q].parent = num;
    45             }
    46         } else tr[now].parent = 0;
    47         last = now;
    48     }
    49     void solve() {
    50         //依赖排序,可以按这个顺序dp
    51         for (int i = 0; i <= num; ++i) sz[i] = 0;
    52         for (int i = 0; i <= num; ++i) sz[tr[i].len]++;
    53         for (int i = 1; i <= num; ++i) sz[i] += sz[i - 1];
    54         for (int i = 0; i <= num; ++i) rnk[--sz[tr[i].len]] = i;
    55         for (int i = num; i >= 1; --i) {
    56             tr[tr[rnk[i]].parent].cnt += tr[rnk[i]].cnt;
    57         }
    58     }
    59     int getAns(char ch[], int len) {
    60         int ans = 1;
    61         int now = 0;
    62         for (int i = 0; i < len; ++i) {
    63             now = tr[now].next[ch[i] - 'A'];
    64             if (now == 0) {
    65                 ++ans;
    66                 now = tr[now].next[ch[i] - 'A'];
    67                 if (now == 0) return -1;
    68             }
    69             //cout<<now<<' ';
    70         }
    71         //cout<<endl;
    72         return ans;
    73     }
    74 };
    75 SAM sam;
    76 char str[500001];
    77 int main() {
    78     scanf("%s", str);
    79     sam.init();
    80     int len = strlen(str);
    81     for (int i = 0; i < len; ++i) sam.add(str[i]);
    82     int n;
    83     scanf("%d", &n);
    84     while (n--) {
    85         scanf("%s", str);
    86         len = strlen(str);
    87         printf("%d
    ", sam.getAns(str, len));
    88     }
    89 }
    View Code

    I:

    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 eps 1e-8
     8 #define lson (curpos<<1)
     9 #define rson (curpos<<1|1)
    10 /* namespace */
    11 using namespace std;
    12 /* header end */
    13 
    14 const int maxn = 2020;
    15 const ll mod = 1e9 + 7;
    16 vector<ll>edge[maxn];
    17 ll n, m, dp[maxn], cnt = 0, ans = 0;
    18 
    19 ll dfs(ll cur) {
    20     if (dp[cur] != -1) return dp[cur];
    21     if (cur > m) {
    22         cnt++;
    23         dp[cur] = 1;
    24         return dp[cur];
    25     }
    26     ll sum = 0;
    27     for (auto x : edge[cur]) sum = ((dfs(x) % mod) + sum) % mod;
    28     dp[cur] = sum;
    29     return sum;
    30 }
    31 
    32 int main() {
    33     for (int i = 0; i < maxn; i++) dp[i] = -1;
    34     scanf("%lld%lld", &n, &m);
    35     for (int i = 1; i <= m; i++) {
    36         ll x; scanf("%lld", &x);
    37         while (x--) {
    38             ll y; scanf("%lld", &y);
    39             edge[i].pb(y);
    40         }
    41         sort(edge[i].begin(), edge[i].end());
    42     }
    43     ll ans = dfs(1);
    44     printf("%lld %lld
    ", ans, cnt);
    45     return 0;
    46 }
    View Code

    K:

    solver:lzh、zyh、czq

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define ff first
     4 #define ss second
     5 typedef long long ll;
     6 typedef pair<int, int> pii;
     7 
     8 char s[10010];
     9 int main() {
    10     scanf("%s", s + 1);
    11     int n = strlen(s + 1);
    12     vector<ll> ans, noteql;
    13     for (int i = 1; i < n; i++)
    14         if (s[i] != s[i + 1])
    15             noteql.push_back(2 * i + 1);
    16     printf("%d
    ", noteql.size());
    17     if (noteql.size() == 0) {
    18         if (s[1] == 'A')
    19             printf("-1
    ");
    20         else
    21             printf("1
    ");
    22         return 0;
    23     }
    24     ans.push_back(1), ans.push_back(-noteql.back()), noteql.pop_back();
    25 
    26     for (auto i : noteql) {
    27         vector<ll> tmp = ans;
    28         tmp.push_back(0);
    29         for (int j = 1; j < tmp.size(); j++)
    30             tmp[j] -= i * ans[j - 1];
    31         ans = tmp;
    32     }
    33     ll f = 1;
    34     if (((noteql.size() + 1) % 2 == 0 && s[1] == 'A') || ((noteql.size() + 1) % 2 == 1 && s[1] == 'H'))
    35         f = -1;
    36     // for (auto i : ans)
    37     // printf("%d ", f * i);
    38     for (int i = 0; i < (int)ans.size(); i++) {
    39         printf("%lld%c", f * ans[i], i == (int)ans.size() - 1 ? '
    ' : ' ');
    40     }
    41     return 0;
    42 }
    View Code

    L:

    solver:lzh、zyh

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define ff first
     4 #define ss second
     5 typedef long long ll;
     6 typedef pair<int, int> pii;
     7 
     8 char s[1010][1010];
     9 int a[1010][1010], b[1010];
    10 int d[20][10000];
    11 int query(int l, int r) {
    12     int t = log2(r - l + 1);
    13     return min(d[t][l], d[t][r - (1 << t) + 1]);
    14 }
    15 void init(int len) {
    16     for (int i = 0; i < len; ++i) {
    17         d[0][i] = b[i];
    18     }
    19     int t = 1;
    20     for (int i = 1; t <= len; ++i) {
    21         for (int j = 0; j + t < len; ++j)
    22             d[i][j] = min(d[i - 1][j], d[i - 1][j + t]);
    23         t <<= 1;
    24     }
    25 }
    26 int main() {
    27     int n, m, ans = 0;
    28     scanf("%d%d", &n, &m);
    29     for (int i = 1; i <= n; i++) {
    30         scanf("%s", s[i] + 1);
    31         for (int j = 1; j <= m; j++) {
    32             if (s[i][j] == 'G')
    33                 a[i][j]++;
    34             a[i][j] += a[i][j - 1];
    35         }
    36     }
    37     for (int j = 1; j <= m; j++) {
    38         for (int i = 1; i <= n; i++) {
    39             int l = j, r = m, mid, tmp = 0;
    40             while (l <= r) {
    41                 mid = l + r >> 1;
    42                 if (a[i][mid] - a[i][j - 1] == 0 || a[i][mid] - a[i][j - 1] == mid - j + 1)
    43                     l = mid + 1, tmp = max(tmp, mid);
    44                 else
    45                     r = mid - 1;
    46             }
    47             b[i - 1] = tmp - j + 1;
    48         }
    49         init(n);
    50         for (int i = 1; i <= n; i++) {
    51             int l = 1, r = n - i + 1, mid, tmp = 1;
    52             while (l <= r) {
    53                 mid = l + r >> 1;
    54                 if (query(i - 1, i + mid - 2) >= mid)
    55                     l = mid + 1, tmp = max(tmp, mid);
    56                 else
    57                     r = mid - 1;
    58             }
    59             ans = max(ans, tmp);
    60         }
    61     }
    62     printf("%d
    ", ans * ans);
    63 }
    View Code

    M:

    solver:lzh

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 #define ff first
     4 #define ss second
     5 typedef long long ll;
     6 typedef pair<int, int> pii;
     7 
     8 int a[1010];
     9 int main() {
    10     int n, x;
    11     cin >> n >> x;
    12     for (int i = 1; i <= n; i++)
    13         cin >> a[i];
    14     int ans = 1;
    15     for (int i = 1; i <= n; i++) {
    16         int tmp = 1;
    17         for (int j = i + 1; j <= n; j++)
    18             if (a[j] - a[j - 1] <= x)
    19                 tmp++;
    20             else
    21                 break;
    22         ans = max(ans, tmp);
    23     }
    24     cout << ans << endl;
    25 }
    View Code
  • 相关阅读:
    自动化测试面试题及答案
    Jmeter读取CSV数据显示EOF问题
    C++中类继承public,protected和private关键字作用详解及派生类的访问权限
    汇编实验:寻址方式在数据访问中的应用
    集成运放综合应用的仿真模拟
    集成运算放大电路线性区运用的仿真实验
    共射/共源放大电路的仿真实验
    二极管特性的仿真实验
    各主流排序算法详细介绍(时间/空间复杂度,适用范围和稳定性)
    三大自由之二 部分
  • 原文地址:https://www.cnblogs.com/JHSeng/p/12347673.html
Copyright © 2020-2023  润新知