UFBA Practice Session for Brazilian ICPC Regionals 2018

Posted jhseng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UFBA Practice Session for Brazilian ICPC Regionals 2018相关的知识,希望对你有一定的参考价值。

差两题AK。

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


B:

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 = 2e3 + 10;
15 char a[maxn], b[maxn];
16 int len1, len2, ans = 0;
17 
18 int main() {
19     scanf("%s%s", a, b);
20     len1 = strlen(a), len2 = strlen(b);
21     set<char>zero, one;
22     zero.clear(), one.clear();
23     for (int i = 0; i <= len1 - len2; i++) {
24         zero.clear(), one.clear();
25         for (int j = 0; j < len2; j++)
26             if (b[j] == 1) one.insert(a[i + j]);
27             else zero.insert(a[i + j]);
28         if ((int)zero.size() > 1 || (int)one.size() > 1) {
29             zero.clear(), one.clear();
30             for (int j = 0; j < len2; j++)
31                 if (b[j] == 1) one.insert(a[len2 + i - 1 - j]);
32                 else zero.insert(a[len2 + i - 1 - j]);
33             if ((int)zero.size() > 1 || (int)one.size() > 1) continue;
34             else ans++;
35         } else {
36             ans++;
37         }
38     }
39     printf("%d
", ans);
40     return 0;
41 }
View Code

C:

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 ll mod = 1e9 + 7;
 9 ll qp(ll base, ll b) {
10     ll res = 1;
11     while (b) {
12         if (b & 1)
13             res = res * base % mod;
14         base = base * base % mod;
15         b >>= 1;
16     }
17     return res;
18 }
19 
20 int main() {
21     int t;
22     cin >> t;
23     while (t--) {
24         ll n;
25         cin >> n;
26         ll ans = ((n - 3) % mod * qp(2, n) % mod + (3 + n) % mod) % mod;
27         cout << ans << "
";
28     }
29 }
View Code

D:

solver:lzh、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 = 2e3 + 10, maxm = 5e4 + 10;
15 int n, m, tot = 1, head[maxn], vis[maxn], cnt[maxn][maxn];
16 vector<pair<int, int>>e, ans;
17 struct Edge {
18     int to, next;
19 } edge[maxm];
20 
21 void add(int from, int to) {
22     edge[++tot].to = to;
23     edge[tot].next = head[from];
24     head[from] = tot;
25 }
26 
27 bool bfs(int s, int t) {
28     for (int i = 0; i < maxn; i++) vis[i] = 0;
29     vis[s] = 1;
30     queue<int>q;
31     while (!q.empty()) q.pop();
32     q.push(s);
33     while (!q.empty()) {
34         int curr = q.front();
35         q.pop();
36         for (int i = head[curr]; i; i = edge[i].next) {
37             int to = edge[i].to;
38             if ((curr == s && to == t) || vis[to]) continue;
39             q.push(to); vis[to] = 1;
40             if (to == t) return false;
41         }
42     }
43     return vis[t] ? false : true;
44 }
45 
46 int main() {
47     scanf("%d%d", &n, &m);
48     for (int i = 1; i <= m; i++) {
49         int x, y; scanf("%d%d", &x, &y);
50         add(x, y); e.pb(mp(x, y)); cnt[x][y]++;
51     }
52     for (auto i : e) {
53         if (cnt[i.first][i.second] > 1) continue;
54         if (bfs(i.first, i.second)) ans.pb(i);
55     }
56     printf("%d
", (int)ans.size());
57     for (auto i : ans) printf("%d %d
", i.first, i.second);
58     return 0;
59 }
View Code

E:

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 vector<int>a;
15 
16 int main() {
17     int x;
18     while (~scanf("%1d", &x)) a.pb(x);
19     if ((int)a.size() == 1) return puts("YES"), 0;
20     int firstOne = a[0], back = 0;
21     for (int i = 1; i < (int)a.size(); i++) back ^= a[i];
22     if (firstOne == back) puts("YES"); else puts("NO");
23     return 0;
24 }
View Code

F:

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 = 1e5 + 10;
15 int n, minSize, maxSize, a[maxn];
16 ll f[maxn];
17 
18 void init() {
19     for (int i = 0; i < maxn; i++) f[i] = 0;
20 }
21 
22 void maintain(int l, int r) {
23     if (l > r) return;
24     f[l]++, f[r + 1]--;
25 }
26 
27 bool check(int x) {
28     init();
29     f[1] = 1, f[2] = -1;
30     queue<int>q;
31     while (!q.empty()) q.pop();
32     for (int i = 1; i <= n; i++) if (a[i] >= x) q.push(i);
33     for (int i = 1; i <= n; i++) {
34         f[i] += f[i - 1];
35         while (!q.empty() && i > q.front()) q.pop();
36         if (!f[i] || q.empty()) continue;
37         if (i + maxSize - 1 < (int)q.front()) continue;
38         maintain(max((int)q.front(), i + minSize - 1) + 1, min(n + 1, i + maxSize - 1 + 1));
39     }
40     f[n + 1] += f[n];
41     return f[n + 1] > 0;
42 }
43 
44 int main() {
45     scanf("%d%d%d", &n, &minSize, &maxSize);
46     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
47     int l = 0, r = INT_MAX, ans = 0;
48     while (l <= r) {
49         int mid = l + r >> 1;
50         if (check(mid)) {
51             ans = mid;
52             l = mid + 1;
53         } else r = mid - 1;
54     }
55     printf("%d
", ans);
56     return 0;
57 }
View Code

G:

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 = 1e5 + 10;
15 const double pi = acos(-1);
16 struct Ship {
17     int visiable;
18     double beta;
19     ll x, y;
20 } a[maxn];
21 int n;
22 double x, alpha, t, ans[maxn];
23 ll d;
24 
25 void fix(double &x) {
26     if (x < 0) x += 360;
27     if (x >= 360) x -= 360;
28 }
29 
30 int main() {
31     scanf("%d%lf", &n, &x);
32     scanf("%lf%lf%lld", &alpha, &t, &d);
33     for (int i = 1; i <= n; i++) {
34         scanf("%lld%lld", &a[i].x, &a[i].y);
35         a[i].visiable = a[i].x * a[i].x + a[i].y * a[i].y <= d * d;
36         a[i].beta = atan2(a[i].y, a[i].x) / pi * 180;
37         fix(a[i].beta); a[i].beta += alpha / 2; fix(a[i].beta);
38     }
39     ll round = (ll)floor(x / t);
40     double timePerRound = alpha / 360 * t, remainTime = x - round * t;
41     for (int i = 1; i <= n; i++) {
42         ans[i] = round * timePerRound;
43         if (a[i].beta < alpha && round) ans[i] -= (alpha - a[i].beta) / alpha * timePerRound;
44     }
45     double minAlpha = remainTime / t * 360, maxAlpha = minAlpha + alpha;
46     for (int i = 1; i <= n; i++) {
47         if (a[i].beta < minAlpha) {
48             ans[i] += timePerRound;
49             if (a[i].beta < alpha && !round) ans[i] -= (alpha - a[i].beta) / alpha * timePerRound;
50         } else if (a[i].beta < maxAlpha) {
51             if (!round) ans[i] += (maxAlpha - alpha) / alpha * timePerRound;
52             else ans[i] += (maxAlpha - a[i].beta) / alpha * timePerRound;
53         }
54         // 如果转过去还大于360
55         if (maxAlpha > 360) {
56             double remainMaxAlpha = maxAlpha - 360;
57             if (a[i].beta < remainMaxAlpha) ans[i] += (remainMaxAlpha - a[i].beta) / alpha * timePerRound;
58         }
59     }
60     for (int i = 1; i <= n; i++) {
61         if (!a[i].visiable) ans[i] = 0;
62         printf("%.11f
", ans[i]);
63     }
64     return 0;
65 }
View Code

H:

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 main() {
 9     int t;
10     cin >> t;
11     while (t--) {
12         ll n;
13         cin >> n;
14         ll ans = 0;
15         for (ll base = 2, j = 1, p = 1; base <= n; base <<= 1, j++, p <<= 1) {
16             ans += n / base * j * p;
17         }
18         cout << ans << "
";
19     }
20 }
View Code

I:

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 val[100010 << 2], pre[100010];
 9 void upd(int x, int curl, int curr, int l, int v) {
10     if (l == curl && curr == curl) {
11         val[x] = v;
12         return;
13     }
14 
15     int mid = curl + curr >> 1;
16     if (l <= mid)
17         upd(x << 1, curl, mid, l, v);
18     else
19         upd(x << 1 | 1, mid + 1, curr, l, v);
20 
21     val[x] = max(val[x << 1], val[x << 1 | 1]);
22 }
23 int que(int x, int curl, int curr, int l, int r) {
24     if (l <= curl && curr <= r) {
25         //printf("que %d %d %d
", curl, curr, val[x]);
26         return val[x];
27     }
28 
29     int mid = curl + curr >> 1;
30     if (r <= mid)
31         return que(x << 1, curl, mid, l, r);
32     else if (l > mid)
33         return que(x << 1 | 1, mid + 1, curr, l, r);
34     else
35         return max(que(x << 1, curl, mid, l, mid),
36                    que(x << 1 | 1, mid + 1, curr, mid + 1, r));
37 }
38 
39 int main() {
40     int n, q;
41     scanf("%d%d", &n, &q);
42     for (int i = 1; i <= n; i++)
43         scanf("%d", &pre[i]);
44     for (int i = 1; i < n; i++)
45         upd(1, 1, n - 1, i, abs(pre[i] - pre[i + 1]));
46     while (q--) {
47         int x, y, z;
48         scanf("%d%d%d", &x, &y, &z);
49         if (x == 1) {
50             pre[y] = z;
51             if (y != 1)
52                 upd(1, 1, n - 1, y - 1, abs(pre[y - 1] - pre[y]));
53             if (y != n)
54                 upd(1, 1, n - 1, y, abs(pre[y] - pre[y + 1]));
55         } else {
56             int ans = 1;
57             if (y != 1) {
58                 int l = 1, r = y - 1, tmp = y;
59                 while (l <= r) {
60                     int mid = l + r >> 1;
61                     if (que(1, 1, n - 1, mid, y - 1) <= z)
62                         r = mid - 1, tmp = min(tmp, mid);
63                     else
64                         l = mid + 1;
65                 }
66                 ans += y - tmp;
67             }
68             if (y != n) {
69                 int l = y, r = n - 1, tmp = y - 1;
70                 while (l <= r) {
71                     int mid = l + r >> 1;
72                     if (que(1, 1, n - 1, y, mid) <= z)
73                         l = mid + 1, tmp = max(tmp, mid);
74                     else
75                         r = mid - 1;
76                 }
77                 ans += tmp - y + 1;
78             }
79             printf("%d
", ans);
80         }
81     }
82 }
View Code

J:

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 = 1e5 + 10;
15 struct Street {
16     int l, r;
17 } str[maxn];
18 int n, k, ans[maxn];
19 vector<int>boss[maxn];
20 
21 /* 树上启发式合并 (CF 741D)----------------------------------------------------------- */
22 // 以下内容全抄
23 int fa[maxn], _size[maxn], remain;
24 
25 void init() {
26     for (int i = 0; i < maxn; i++) _size[i] = 1, fa[i] = i;
27 }
28 
29 int findFa(int x) {
30     return x == fa[x] ? x : (fa[x] = findFa(fa[x]));
31 }
32 
33 void cleanInfo(int x) {
34     fa[str[x].l] = str[x].l, fa[str[x].r] = str[x].r;
35     for (int i : boss[x]) cleanInfo(i);
36 }
37 
38 void merge(int x, int y) {
39     int fx = findFa(x), fy = findFa(y);
40     if (fx != fy) fa[fx] = fy, remain--;
41 }
42 
43 void solve(int x) {
44     merge(str[x].l, str[x].r);
45     for (auto i : boss[x]) solve(i);
46 }
47 
48 void dfs(int x) {
49     int heavySon = -1;
50     // 从最小的size开始处理
51     for (auto i : boss[x]) if (_size[heavySon] < _size[i] || heavySon == -1) heavySon = i;
52     for (auto i : boss[x]) {
53         if (i == heavySon) continue;
54         remain = k;
55         dfs(i), cleanInfo(i); // dfs后不要忘记清除信息!
56     }
57     remain = k;
58     if (heavySon != -1) dfs(heavySon);
59     for (auto i : boss[x]) if (i != heavySon) solve(i);
60     merge(str[x].l, str[x].r);
61     ans[x] = remain;
62 }
63 
64 /* ----------------------------------------------------------------------------------- */
65 
66 int main() {
67     init();
68     scanf("%d%d", &n, &k);
69     for (int i = 2; i <= n; i++) {
70         int x; scanf("%d", &x);
71         boss[x].pb(i);
72     }
73     for (int i = 1; i <= n; i++) scanf("%d%d", &str[i].l, &str[i].r);
74     for (int i = n; i >= 1; i--) {
75         for (auto j : boss[i]) _size[i] += _size[j];
76     }
77     dfs(1);
78     for (int i = 1; i <= n; i++) printf("%d
", ans[i]);
79     return 0;
80 }
View Code

K:

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[100010];
 9 int main() {
10     int n;
11     scanf("%d", &n);
12     for (int i = 1; i <= n; i++) {
13         scanf("%d", &a[i]);
14         a[i] += a[i - 1];
15     }
16     for (int i = 1; i <= n; i++) {
17         int ans = 0, j = i - 1, add = 3;
18         while (j <= n) {
19             int r = j + add;
20             if (r > n)
21                 r = n;
22             ans += max(0, a[r] - a[j]);
23             j += add;
24             add += 3;
25         }
26         printf("%d
", ans);
27     }
28 }
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 vector<pii> v[15];
 9 int main()
10 {
11     int n;
12     scanf("%d", &n);
13     int add = 64, j = 1;
14     if (add > n) {
15         printf("1
1
1 %d
", n);
16         return 0;
17     }
18     while (add <= n) {
19         int cur = 1;
20         while (1) {
21             v[j].push_back({ cur, min(n, cur - 1 + add) });
22             cur += add;
23             if (cur > n)
24                 break;
25         }
26         add = add * 4;
27         j++;
28     }
29     v[j].push_back({ 1, n });
30     printf("%d
", j);
31     for (int i = 1; i <= j; i++) {
32         printf("%d
", v[i].size());
33         for (auto p : v[i])
34             printf("%d %d
", p.ff, p.ss);
35     }
36 }
View Code

 

以上是关于UFBA Practice Session for Brazilian ICPC Regionals 2018的主要内容,如果未能解决你的问题,请参考以下文章

1.1.1 A+B for Input-Output Practice (I)

1002: A+B for Input-Output Practice (II)

hdu 1095 A+B for Input-Output Practice (VII)

hdu 1092 A+B for Input-Output Practice (IV)

hdu 1096 A+B for Input-Output Practice (VIII)

hdu 1093 A+B for Input-Output Practice (V)