其他分享
首页 > 其他分享> > UFPE Starters Final Try-Outs 2020

UFPE Starters Final Try-Outs 2020

作者:互联网

题目很简单。差点10题,非常可惜。


A:

签到题+4不应该。

solver:lzh

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, int> pii;
 4 typedef long long ll;
 5 #define ff first
 6 #define ss second
 7 
 8 const int MAXSTRLEN = 500010;
 9 int maxlen0 = 0, maxlen1 = 0;
10 char ch[2 * MAXSTRLEN];
11 int p[2 * MAXSTRLEN];
12 void manacher(char str[], int len) {
13     for (int i = 0; i < len; i++) {
14         ch[2 * i + 1] = '#';
15         ch[2 * i + 2] = str[i];
16     }
17     ch[0] = '$';
18     ch[2 * len + 1] = '#';
19     ch[2 * len + 2] = '\0';
20     len = len * 2 + 2;
21     p[0] = p[1] = 1;
22     int id = 1, mx = 2;
23     for (int i = 2; i < len; i++) {
24         int j = min(p[2 * id - i], mx - i);
25         while (ch[i - j] == ch[i + j])
26             j++;
27         p[i] = j;
28         if (i + p[i] > mx) {
29             id = i;
30             mx = i + p[i];
31         }
32         if ((p[i] - 1) % 2 == 0)
33             maxlen0 = max(maxlen0, p[i] - 1);
34         else
35             maxlen1 = max(maxlen1, p[i] - 1);
36     }
37 }
38 char s[MAXSTRLEN];
39 int main() {
40     int n, m;
41     scanf("%d%d%s", &n, &m, s);
42     manacher(s, n);
43     if ((m % 2 == 0 && maxlen0 >= m) || (m % 2 == 1 && maxlen1 >= m)) {
44         printf("Accept\n");
45     } else
46         printf("Reject\n");
47 }
View Code

B:

solver:zyh、czq

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 struct Segment_Tree {
 4     //constants and innerclass
 5     struct node {
 6         int l, r, lc, rc;
 7         long long val;
 8     };
 9     static const int N = 500000;
10     static const int root = 0;
11 
12     //variables
13     int num;
14     node tr[2 * N];
15 
16     //methods
17     void setRange(int l, int r, int now = root) {
18         num = 0;
19         build(l, r, now);
20     }
21     void build(int l, int r, int now) {
22         tr[now].l = l; tr[now].r = r; tr[now].val = 0;
23         if (l < r) {
24             int mid = (l + r) >> 1;
25             ++num; tr[now].lc = num;
26             ++num; tr[now].rc = num;
27             build(l, mid, tr[now].lc);
28             build(mid + 1, r, tr[now].rc);
29         }
30     }
31 
32     void pushup(node &f, node &lc, node &rc) {
33         f.val = lc.val + rc.val;
34     }
35 
36     //warning: don't invoke both update and updateR in single segment tree, it may cause error
37     void update(int pos, long long val, int now = root) {
38         int mid = (tr[now].l + tr[now].r) >> 1;
39         if (tr[now].l == tr[now].r) {
40             tr[now].val = val;
41             return;
42         } else if (pos <= mid) update(pos, val, tr[now].lc);
43         else update(pos, val, tr[now].rc);
44         //write parent update here
45         pushup(tr[now], tr[tr[now].lc], tr[tr[now].rc]);
46     }
47 
48     long long query(int l, int r, int now = root) {
49         if (tr[now].l == l && tr[now].r == r) return tr[now].val;
50         else {
51             //if (tr[now].cover!=0) pushdown(tr[now],tr[tr[now].lc],tr[tr[now].rc]);
52             int mid = (tr[now].l + tr[now].r) >> 1;
53             if (r <= mid) return query(l, r, tr[now].lc);
54             else if (l > mid) return query(l, r, tr[now].rc);
55             else return query(l, mid, tr[now].lc) + query(mid + 1, r, tr[now].rc);
56         }
57     }
58 
59 };
60 Segment_Tree tr;
61 map<string, long long> Map;
62 string str[1000001];
63 char ch[10001];
64 int main() {
65     int n, m, q;
66     scanf("%d%d%d", &n, &m, &q);
67     for (int i = 1; i <= n; ++i) {
68         scanf("%s", ch);
69         str[i] = ch;
70     }
71     for (int i = 0; i < m; ++i) {
72         long long v;
73         scanf("%s%lld", ch, &v);
74         Map[string(ch)] = v;
75     }
76     tr.setRange(1, n);
77     for (int i = 1; i <= n; ++i) {
78         tr.update(i, Map[str[i]]);
79     }
80     while (q--) {
81         int op;
82         scanf("%d", &op);
83         if (op == 1) {
84             int x;
85             scanf("%d%s", &x, ch);
86             tr.update(x, Map[string(ch)]);
87         } else {
88             int l, r;
89             scanf("%d%d", &l, &r);
90             long long s = tr.query(l, r);
91             if (s <= 30 * (r - l + 1)) printf("NO\n");
92             else printf("YES\n");
93         }
94     }
95 }
View Code

D:

solver:lzh、czq

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef pair<double, int> pii;
 5 #define ff first
 6 #define ss second
 7 #define mp make_pair
 8 
 9 pii p[100010];
10 int check(double x, int n) {
11     int cur = 1;
12     while (cur <= n) {
13         ll add = 0;
14         while (p[cur].ff - x <= 0)
15             add += p[cur++].ss;
16         if (add == 0)
17             return 0;
18         x += add;
19     }
20     return 1;
21 }
22 int main() {
23     int n, x, y;
24     scanf("%d%d%d", &n, &x, &y);
25     for (int i = 1; i <= n; i++) {
26         int u, v, w;
27         scanf("%d%d%d", &u, &v, &w);
28         p[i] = mp(sqrt(1ll * (u - x) * (u - x) + 1ll * (v - y) * (v - y)) - w, w);
29     }
30     sort(p + 1, p + 1 + n);
31 
32     double l = max(0.0, p[1].ff), r = p[n].ff, eps = 1e-8;
33     double ans = r;
34     while (r - l > eps) {
35         double mid = (l + r) / 2.0;
36         if (check(mid, n)) {
37             r = mid;
38             ans = min(ans, mid);
39         } else
40             l = mid;
41     }
42     printf("%.10lf\n", ans);
43 }
View Code

E:

solver:zyh

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int li[] = {6, 28, 496, 8128};
 4 int len = 4;
 5 inline int read() {
 6     int rnt = 0;
 7     int sign = 0;
 8     char ch = 0;
 9     while (!isdigit(ch)) {
10         sign |= ch == '-';
11         ch = getchar();
12     }
13     while (isdigit(ch)) rnt = (rnt << 3) + (rnt << 1) + (ch ^ 48), ch = getchar();
14     return sign ? -rnt : rnt;
15 }
16 inline void print(int x) {
17     if (x < 0) {
18         putchar('-');
19         x = -x;
20     }
21     if (x > 9) print(x / 10);
22     putchar(x % 10 + '0');
23 }
24 int main() {
25     int n = read();
26     while (n--) {
27         int k = read();
28         int ans;
29         for (ans = len - 1; ans >= 0; --ans)
30             if (li[ans] <= k) break;
31         if (ans < 0) print(-1);
32         else print(li[ans]);
33         putchar('\n');
34     }
35 }
View Code

F:

solver:lzh

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, int> pii;
 4 typedef long long ll;
 5 #define ff first
 6 #define ss second
 7 
 8 struct node {
 9     int l, r, h;
10     int add;
11     node() {}
12     node(int _l, int _r, int _h, int _add): l(_l), r(_r), h(_h), add(_add) {}
13 };
14 
15 const int N = 2e5 + 10;
16 int x[N];
17 ll sum[N << 2];
18 node q[N];
19 int mark[N << 2];
20 
21 void pushup(int n, int left, int right) {
22     if (mark[n])sum[n] = x[right + 1] - x[left];
23     else if (left == right)sum[n] = 0;
24     else sum[n] = sum[n << 1] + sum[n << 1 | 1];
25 }
26 
27 void pushdown(int n) {
28     mark[n << 1] += mark[n], mark[n << 1 | 1] += mark[n];
29     mark[n] = 0;
30 }
31 
32 void update(int l, int r, int add, int n, int left, int right) {
33     if (l <= left && right <= r) {
34         mark[n] += add;
35         pushup(n, left, right);
36         return;
37     }
38     int mid = left + right >> 1;
39     if (l <= mid)update(l, r, add, n << 1, left, mid);
40     if (mid < r)update(l, r, add, n << 1 | 1, mid + 1, right);
41     pushup(n, left, right);
42 }
43 
44 int main() {
45     int n;
46     scanf("%d", &n);
47     for (int i = 1; i <= n; i++) {
48         int l, r, h; scanf("%d%d%d", &l, &r, &h);
49         x[2 * i - 1] = l; x[2 * i] = r;
50         q[2 * i - 1] = node(l, r, 0, 1);
51         q[2 * i] = node(l, r, h, -1);
52     }
53     sort(x + 1, x + 1 + 2 * n);
54     sort(q + 1, q + 1 + 2 * n, [](node a, node b) {
55         return a.h < b.h;
56     });
57     int cnt = 1;
58     for (int i = 2; i <= 2 * n; i++)
59         if (x[i - 1] != x[i])x[++cnt] = x[i];
60     ll ans = 0;
61     q[2 * n + 1].h = q[2 * n].h;
62 
63     for (int i = 1; i <= 2 * n; i++) {
64         int l = lower_bound(x + 1, x + 1 + cnt, q[i].l) - x;
65         int r = lower_bound(x + 1, x + 1 + cnt, q[i].r) - x - 1;
66         update(l, r, q[i].add, 1, 1, cnt);
67         ans += sum[1] * (q[i + 1].h - q[i].h);
68     }
69     printf("%lld\n", ans);
70 }
View Code

G:

solver:lzh、czq

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, int> pii;
 4 typedef long long ll;
 5 #define ff first
 6 #define ss second
 7 
 8 map<string, int>name, prob;
 9 char strname[50010][25];
10 int pts[50010];
11 set<int>submit[50010];
12 int main() {
13     int c, p, s; scanf("%d%d%d", &c, &p, &s);
14     int cname = 0, cprob = 0;
15     char str[50];
16     for (int i = 1; i <= c; i++) {
17         scanf("%s", strname[i]);
18         name[strname[i]] = ++cname;
19     }
20     for (int i = 1; i <= p; i++) {
21         int x;
22         scanf("%s%d", str, &x);
23         prob[str] = ++cprob; pts[cprob] = x;
24     }
25     for (int i = 1; i <= s; i++) {
26         int numname = -1, numprob = -1;
27         scanf("%s", str);
28         numname = name[str];
29         scanf("%s", str);
30         numprob = prob[str];
31         scanf("%s", str);
32         if (strlen(str) == 2 && str[0] == 'A' && str[1] == 'C') {
33             if (numname && numprob) {
34                 submit[numname].insert(numprob);
35             }
36         }
37     }
38     for (int i = 1; i <= c; i++) {
39         int ans = 0;
40         for (auto j : submit[i])ans += pts[j];
41         printf("%s %d\n", strname[i], ans);
42     }
43 }
View Code

H:

solver:lzh、czq

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef pair<ll, int> pii;
 5 #define ff first
 6 #define ss second
 7 #define mp make_pair
 8 
 9 const int N = 1e5 + 10;
10 vector<pii> v[N];
11 int T[N], vis[N];
12 ll ans[N];
13 int main() {
14     int n, m, k;
15     scanf("%d%d%d", &n, &m, &k);
16     for (int i = 1; i <= m; i++) {
17         int x, y, z;
18         scanf("%d%d%d", &x, &y, &z);
19         v[x].push_back(mp(y, z));
20         v[y].push_back(mp(x, z));
21     }
22     for (int i = 1; i <= n; i++)
23         scanf("%d", &T[i]);
24 
25     priority_queue<pii, vector<pii>, greater<pii>> pq;
26     for (int i = 1; i <= k; i++) {
27         int x;
28         scanf("%d", &x);
29         pq.push(mp(T[x], x));
30     }
31 
32     while (!pq.empty()) {
33         pii x = pq.top();
34         pq.pop();
35         if (vis[x.ss])
36             continue;
37         vis[x.ss]++;
38         ans[x.ss] = x.ff;
39 
40         for (auto i : v[x.ss])
41             if (!vis[i.ff])
42                 pq.push(mp(x.ff + i.ss + T[i.ff], i.ff));
43     }
44     for (int i = 1; i <= n; i++)
45         printf("%lld\n", ans[i]);
46 }
View Code

I:

solver:zyh、czq

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 struct point {
 4     int x, v;
 5     point() {}
 6     point(int _x, int _v) {
 7         x = _x;
 8         v = _v;
 9     }
10     bool operator<(const point &b)const {
11         return v < b.v;
12     }
13 };
14 point pts[2000000];
15 int f[2000000];
16 int Size[2000000];
17 int a[2000000];
18 int find(int u) {
19     if (f[u] != u) f[u] = find(f[u]);
20     return f[u];
21 }
22 int Union(int u, int v) {
23     u = find(u);
24     v = find(v);
25     if (u != v) {
26         Size[u] += Size[v];
27         f[v] = u;
28     }
29     return u;
30 }
31 int main() {
32     int s, n, m;
33     scanf("%d%d%d", &s, &n, &m);
34     int len = n * m;
35     for (int i = 0; i < len; ++i) {
36         scanf("%d", &a[i]);
37         pts[i] = point(i, a[i]);
38     }
39     sort(pts, pts + len);
40     for (int i = 0; i < len; ++i) {
41         f[i] = i; Size[i] = 1;
42     }
43     int maxsize = 0;
44     for (int k = len - 1; k >= 0; --k) {
45         int i = pts[k].x;
46         int v = pts[k].v;
47         if (i - 1 >= 0 && (i / m) == ((i - 1) / m) && a[i - 1] >= v) Union(i, i - 1);
48         if (i + 1 < len && (i / m) == ((i + 1) / m) && a[i + 1] >= v) Union(i, i + 1);
49         if (i + m < len && a[i + m] >= v) Union(i, i + m);
50         if (i - m >= 0 && a[i - m] >= v) Union(i, i - m);
51         maxsize = max(maxsize, Size[find(i)]);
52         if (maxsize >= s) {
53             printf("%d\n", v);
54             return 0;
55         }
56     }
57 }
View Code

J:

solver:lzh

差一点就做出来了,非常难顶

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 typedef pair<int, int> pii;
  4 typedef long long ll;
  5 #define ff first
  6 #define ss second
  7 #define mp make_pair
  8 
  9 vector<pii> v[100010];
 10 ll dp[100010][10];
 11 const ll mod = 1e9 + 7;
 12 int baoli2[20][2] = { 1, 2, 1, 3, 1, 4, 1, 5, 2, 1, 2, 3, 2, 4, 2, 5, 3, 1, 3, 2, 3, 4, 3, 5, 4, 1, 4, 2, 4, 3, 4, 5, 5, 1, 5, 2, 5, 3, 5, 4 };
 13 int baoli3[60][3] = { 1, 2, 3, 1, 2, 4, 1, 2, 5, 1, 3, 2, 1, 3, 4, 1, 3, 5, 1, 4, 2, 1, 4, 3, 1, 4, 5, 1, 5, 2, 1, 5, 3, 1, 5, 4, 2, 1, 3, 2, 1, 4, 2, 1, 5, 2, 3, 1, 2, 3, 4, 2, 3, 5, 2, 4, 1, 2, 4, 3, 2, 4, 5, 2, 5, 1, 2, 5, 3, 2, 5, 4, 3, 1, 2, 3, 1, 4, 3, 1, 5, 3, 2, 1, 3, 2, 4, 3, 2, 5, 3, 4, 1, 3, 4, 2, 3, 4, 5, 3, 5, 1, 3, 5, 2, 3, 5, 4, 4, 1, 2, 4, 1, 3, 4, 1, 5, 4, 2, 1, 4, 2, 3, 4, 2, 5, 4, 3, 1, 4, 3, 2, 4, 3, 5, 4, 5, 1, 4, 5, 2, 4, 5, 3, 5, 1, 2, 5, 1, 3, 5, 1, 4, 5, 2, 1, 5, 2, 3, 5, 2, 4, 5, 3, 1, 5, 3, 2, 5, 3, 4, 5, 4, 1, 5, 4, 2, 5, 4, 3 };
 14 
 15 void dfs(int x, int pre) {
 16     int col = 0;
 17     vector<int> nex;
 18     for (auto i : v[x])
 19         if (i.ff != pre) {
 20             dfs(i.ff, x);
 21             nex.push_back(i.ff);
 22         } else
 23             col = i.ss;
 24     int sz = v[x].size();
 25     if (pre == -1)
 26         return;
 27 
 28     if (sz == 1) {
 29         if (v[x][0].ss)
 30             dp[x][v[x][0].ss] = 1;
 31         else
 32             for (int i = 1; i <= 5; i++)
 33                 dp[x][i] = 1;
 34         return;
 35     } else if (sz == 2) {
 36         for (int i = 0; i < 20; i++)
 37             if (!col || col == baoli2[i][1]) {
 38                 dp[x][baoli2[i][1]] = (dp[x][baoli2[i][1]] + dp[nex[0]][baoli2[i][0]]) % mod;
 39             }
 40     } else if (sz == 3) {
 41         for (int i = 0; i < 60; i++)
 42             if (!col || col == baoli3[i][2]) {
 43                 dp[x][baoli3[i][2]] = (dp[x][baoli3[i][2]] + dp[nex[0]][baoli3[i][0]] * dp[nex[1]][baoli3[i][1]] % mod) % mod;
 44             }
 45     } else {
 46         int a[10];
 47         for (int i = 1; i <= 5; i++)
 48             a[i] = i;
 49         do {
 50             if (!col || col == a[sz]) {
 51                 ll tmp = 1;
 52                 for (int i = 1; i <= sz - 1; i++)
 53                     tmp = tmp * dp[nex[i - 1]][a[i]] % mod;
 54 
 55                 dp[x][a[sz]] = (dp[x][a[sz]] + tmp) % mod;
 56             }
 57         } while (next_permutation(a + 1, a + 1 + 5));
 58     }
 59 }
 60 int main() {
 61     int n;
 62     scanf("%d", &n);
 63     for (int i = 1; i <= n - 1; i++) {
 64         int a, b, c;
 65         scanf("%d%d%d", &a, &b, &c);
 66         v[a].push_back(mp(b, c));
 67         v[b].push_back(mp(a, c));
 68     }
 69     for (int i = 1; i <= n; i++)
 70         if (v[i].size() > 5) {
 71             printf("0\n");
 72             return 0;
 73         }
 74     if (n == 1) {
 75         printf("1\n");
 76         return 0;
 77     }
 78     if (n == 2) {
 79         if (v[1][0].ss)
 80             printf("1\n");
 81         else
 82             printf("5\n");
 83         return 0;
 84     }
 85     dfs(1, -1);
 86 
 87     ll ans = 0;
 88     vector<int> nex;
 89     for (auto i : v[1])
 90         nex.push_back(i.ff);
 91     if (v[1].size() == 1) {
 92         for (int i = 1; i <= 5; i++) {
 93             ans = (ans + dp[nex[0]][i]) % mod;
 94         }
 95     } else if (v[1].size() == 2) {
 96         for (int i = 0; i < 20; i++) {
 97             ll tmp = 1;
 98             for (int j = 0; j < 2; j++)
 99                 tmp = tmp * dp[nex[j]][baoli2[i][j]] % mod;
100             ans = (ans + tmp) % mod;
101         }
102     } else if (v[1].size() == 3) {
103         for (int i = 0; i < 60; i++) {
104             ll tmp = 1;
105             for (int j = 0; j < 3; j++)
106                 tmp = tmp * dp[nex[j]][baoli3[i][j]] % mod;
107             ans = (ans + tmp) % mod;
108         }
109     } else {
110         int a[10], sz = v[1].size();
111         for (int i = 1; i <= 5; i++)
112             a[i] = i;
113         do {
114             ll tmp = 1;
115             for (int i = 1; i <= sz; i++)
116                 tmp = tmp * dp[nex[i - 1]][a[i]] % mod;
117             ans = (ans + tmp) % mod;
118         } while (next_permutation(a + 1, a + 1 + 5));
119     }
120 
121     printf("%lld\n", ans);
122 }
View Code

K:

solver:lzh、czq

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

标签:UFPE,Outs,10,int,tr,long,Starters,now,define
来源: https://www.cnblogs.com/JHSeng/p/12193790.html