2018 IME Tryouts

比较简单的三星场,差一点AK

最近忙着面试,三个人都不在状态,我前期很C后期萎了,两个队友前期很萎后面很C,可能这就是队内文化8

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


A:

solver:zyh、lzh

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 long long dp[2][8];
 4 const long long M = 1e9 + 7;
 5 int main() {
 6     int n;
 7     scanf("%d", &n);
 8     dp[1][0] = dp[1][6] = dp[1][3] = 1;
 9     for (int i = 2; i <= n; ++i) {
10         int now = i & 1;
11         int pre = (i - 1) & 1;
12         dp[now][7] = (dp[pre][0] + dp[pre][6] + dp[pre][3]) % M;
13         dp[now][6] = (dp[pre][1] + dp[pre][7]) % M;
14         dp[now][5] = dp[pre][2];
15         dp[now][4] = dp[pre][3];
16         dp[now][3] = (dp[pre][4] + dp[pre][7]) % M;
17         dp[now][2] = dp[pre][5];
18         dp[now][1] = dp[pre][6];
19         dp[now][0] = dp[pre][7];
20         //cout<<dp[now][7]<<endl;
21     }
22     printf("%lld", dp[n & 1][7]);
23 }
View Code

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 string s, ans = "";
15 int numC = 0, numS = 0;
16 
17 int main() {
18     ios::sync_with_stdio(false);
19     cin.tie(0);
20     cin >> s;
21     for (auto ch : s) {
22         if (ch == 'C' && numC <= 1) {
23             numC++, numS = 0;
24             ans += 'B';
25         } else if (ch == 'S' && numS <= 1) {
26             numS++, numC = 0;
27             ans += 'D';
28         } else if (ch == 'C') {
29             numC = 0, ans += 'P';
30         } else if (ch == 'S') {
31             numS = 0, ans += 'T';
32         }
33     }
34     cout << ans << endl;
35     return 0;
36 }
View Code

C:

solver:lzh

据说这个题随便剪一下枝就能过了,跑得飞起

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef pair<int, int> pii;
 5 #define ff first
 6 #define ss second
 7 
 8 int a[10][10], ok = 0;
 9 int w[10][10], quyu[40], num[40];
10 int rvis[10][10], cvis[10][10], blockvis[10][10], quyuvis[40][10];
11 inline int getblock(int x, int y) {
12     return (x + 1) / 2 * 2 - (y > 3 ? 0 : 1);
13 }
14 void dfs(int x, int y) {
15     if (y == 7) {
16         x++, y = 1;
17         dfs(x, y);
18         return;
19     }
20     if (ok)
21         return;
22     if (x == 7) {
23         for (int i = 1; i <= 6; i++)
24             for (int j = 1; j <= 6; j++)
25                 cout << a[i][j] << " \n"[j == 6];
26         ok = 1;
27         return;
28     }
29 
30     if (num[w[x][y]] == 1) {
31         int v = w[x][y], b = getblock(x, y), p = quyu[v];
32         if (!rvis[x][p] && !cvis[y][p] && !blockvis[b][p] && !quyuvis[v][p]) {
33             a[x][y] = p;
34             quyu[v] = 0, num[v] = 0;
35             rvis[x][p] = cvis[y][p] = blockvis[b][p] = quyuvis[v][p] = 1;
36             dfs(x, y + 1);
37             rvis[x][p] = cvis[y][p] = blockvis[b][p] = quyuvis[v][p] = 0;
38             quyu[v] = p, num[v] = 1;
39             a[x][y] = 0;
40         }
41         return;
42     }
43     for (int i = 1; i <= min(quyu[w[x][y]] - 1, 6); i++) {
44         int v = w[x][y], b = getblock(x, y), p = i;
45         if (!rvis[x][p] && !cvis[y][p] && !blockvis[b][p] && !quyuvis[v][p]) {
46             a[x][y] = p;
47             quyu[v] -= p, num[v]--;
48             rvis[x][p] = cvis[y][p] = blockvis[b][p] = quyuvis[v][p] = 1;
49             dfs(x, y + 1);
50             rvis[x][p] = cvis[y][p] = blockvis[b][p] = quyuvis[v][p] = 0;
51             quyu[v] += p, num[v]++;
52             a[x][y] = 0;
53         }
54     }
55 }
56 
57 int main() {
58     int n;
59     cin >> n;
60     for (int i = 1; i <= n; i++)
61         cin >> quyu[i];
62     for (int i = 1; i <= 6; i++)
63         for (int j = 1, x; j <= 6; j++) {
64             cin >> x;
65             w[i][j] = x, num[x]++;
66         }
67     dfs(1, 1);
68 }
View Code

D:

solver:zyh、czq

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 long long sum(long long x) {
 4     return x * (x + 1) / 2LL;
 5 }
 6 int main() {
 7     int T;
 8     scanf("%d", &T);
 9     while (T--) {
10         long long n;
11         scanf("%lld", &n);
12         long long l = -1, r = (long long)sqrt(4 * (n + 1)) + 1;
13         while (l + 1 < r) {
14             long long mid = l + r >> 1;
15             if (sum(mid) <= n) l = mid;
16             else r = mid;
17         }
18         printf("%lld\n", l);
19     }
20     return 0;
21 }
View Code

E:

solver:lzh

最后绝杀AC,lzhnb

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3 typedef long long ll;
  4 typedef pair<int, int> pii;
  5 #define ff first
  6 #define ss second
  7 
  8 const int N = 1 << 18;
  9 const double PI = acos(-1.0);
 10 
 11 struct cpx {
 12     double x, y;
 13     cpx() {}
 14     cpx(double _x, double _y)
 15         : x(_x)
 16         , y(_y) {
 17     }
 18     cpx operator+(const cpx &b) const {
 19         return cpx(x + b.x, y + b.y);
 20     }
 21     cpx operator-(const cpx &b) const {
 22         return cpx(x - b.x, y - b.y);
 23     }
 24     cpx operator*(const cpx &b) const {
 25         return cpx(x * b.x - y * b.y, x * b.y + y * b.x);
 26     }
 27     cpx operator/(const int &b) const {
 28         return cpx(x / b, y / b);
 29     }
 30 };
 31 
 32 int rev[2 * N + 10];
 33 void getrev(int len) {
 34     int bit = 0;
 35     while ((1 << bit) < len)
 36         bit++;
 37     for (int i = 0; i < len; i++)
 38         rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
 39 }
 40 
 41 void fft(cpx x[], int len, int opt) {
 42     for (int i = 0; i < len; i++)
 43         if (i < rev[i])
 44             swap(x[i], x[rev[i]]);
 45     for (int mid = 1; mid < len; mid <<= 1) {
 46         cpx tmp(cos(PI / mid), opt * sin(PI / mid));
 47         for (int i = 0, add = mid << 1; i < len; i += add) {
 48             cpx base(1, 0);
 49             for (int j = i; j < i + mid; j++, base = base * tmp) {
 50                 cpx a = x[j], b = base * x[j + mid];
 51                 x[j] = a + b, x[j + mid] = a - b;
 52             }
 53         }
 54     }
 55 
 56     if (opt == -1)
 57         for (int i = 0; i < len; i++)
 58             x[i] = x[i] / len;
 59 }
 60 
 61 cpx ffta[2 * N + 10], fftb[2 * N + 10];
 62 int solve(int a[], int b[], int lena, int lenb) {
 63     int len = 1;
 64     while (len < lena + lenb)
 65         len <<= 1;
 66     getrev(len);
 67 
 68     for (int i = 0; i < lena; i++)
 69         ffta[i] = cpx(a[i], 0);
 70     for (int i = lena; i < len; i++)
 71         ffta[i] = cpx(0, 0);
 72     for (int i = 0; i < lenb; i++)
 73         fftb[i] = cpx(b[i], 0);
 74     for (int i = lenb; i < len; i++)
 75         fftb[i] = cpx(0, 0);
 76 
 77     fft(ffta, len, 1), fft(fftb, len, 1);
 78     for (int i = 0; i < len; i++)
 79         ffta[i] = ffta[i] * fftb[i];
 80     fft(ffta, len, -1);
 81     return len;
 82 }
 83 
 84 char p[200010], t[200010];
 85 ll dam[N * 2 + 10], ans[N];
 86 const char s1[] = { "RNE" }, s2[] = { "ABC" };
 87 int numa[200010], numb[200010], D[10];
 88 int main() {
 89     int a, b, c, h;
 90     scanf("%d%d%d%d", &D[0], &D[1], &D[2], &h);
 91     scanf("%s%s", p + 1, t + 1);
 92     int n = strlen(p + 1), m = strlen(t + 1);
 93     for (int i = 0; i < 3; i++) {
 94         for (int j = 0; j <= n; j++)
 95             numa[j] = numb[j] = 0;
 96         for (int j = 1; j <= n; j++)
 97             if (p[j] == s1[i])
 98                 numa[j]++;
 99         for (int j = 1; j <= m; j++)
100             if (t[j] == s2[i])
101                 numb[n - j + 1]++;
102         int len = solve(numa, numb, n + 4, n + 4);
103         for (int j = 0; j < len; j++)
104             dam[j] += (ll)(ffta[j].x + 0.5) * D[i];
105         //for (int j = 0; j < len; j++)
106         //    printf("%d %d %lf\n", numa[j], numb[j], ffta[i].x);
107     }
108     int ansn = 0;
109     for (int i = 0; i < 2 * N; i++) {
110         ans[i % n] += dam[i];
111     }
112     for (int i = 0; i < n; i++) {
113         if (ans[i] >= h)
114             ansn++;
115         //printf("%lld ", ans[i]);
116     }
117     int g = __gcd(ansn, n);
118     printf("%d %d\n", ansn / g, n / g);
119 }
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 pair<int, int>edge[MAXN];
16 int n, m, cnt, fa[MAXN], p[MAXN], ans[MAXN];
17 
18 int main() {
19     scanf("%d%d", &n, &m); cnt = n;
20     for (int i = 1; i <= n; i++) fa[i] = i;
21     for (int i = 1, u, v; i <= m; i++) {
22         scanf("%d%d", &u, &v);
23         edge[i] = mp(u, v);
24     }
25 
26     function<int(int)>findFa = [&](int cur)->int{
27         return fa[cur] == cur ? cur : fa[cur] = findFa(fa[cur]);
28     };
29 
30     for (int i = 1; i <= m; i++) scanf("%d", &p[i]);
31     for (int i = m; i >= 1; i--) {
32         ans[i] = cnt;
33         int fa1 = findFa(edge[p[i]].first), fa2 = findFa(edge[p[i]].second);
34         if (fa1 != fa2) {
35             fa[fa1] = fa2;
36             cnt--;
37         }
38     }
39     for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
40     return 0;
41 }
View Code

G:

补:zyh

思路完全正确,队友写挂了,比赛最后三分钟被我对拍拍出错误,但是没时间改

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int id[500001];
 4 vector<int> factors[500001];
 5 bool inSet[500001];
 6 long long cnt[1000001];
 7 void getFactors(int x, vector<int> &factor) {
 8     int len = sqrt(x);
 9     for (int i = 2; i <= len; ++i)
10         if (x % i == 0) {
11             factor.push_back(i);
12             if (i * i != x) factor.push_back(x / i);
13         }
14     factor.push_back(x);
15 }
16 void updateCnt(vector<int> &factor, int d) {
17     for (auto x : factor) {
18         cnt[x] += d;
19     }
20 }
21 void getPrime(int n, vector<int> &prime) {
22     prime.clear();
23     int len = sqrt(n);
24     for (int i = 2; i <= len; ++i)
25         if (n % i == 0) {
26             prime.push_back(i);
27             while (n % i == 0) n /= i;
28         }
29     if (n > 1) prime.push_back(n);
30 }
31 void dfs(int st, int sel, int product, long long &s, vector<int> &prime, int len) {
32     if (sel > 0) {
33         if (sel & 1) s += cnt[product];
34         else s -= cnt[product];
35     }
36     for (int i = st; i < len; ++i) {
37         dfs(i + 1, sel + 1, product * prime[i], s, prime, len);
38     }
39 }
40 long long howMany(int x) {
41     vector<int> prime;
42     getPrime(x, prime);
43     int len = prime.size();
44     long long rnt = 0;
45     dfs(0, 0, 1, rnt, prime, len);
46     //cout<<"howMany: "<<rnt<<endl;
47     return rnt;
48 }
49 int main() {
50     int n, T;
51     scanf("%d%d", &n, &T);
52     for (int i = 0; i < n; ++i) {
53         scanf("%d", &id[i]);
54         getFactors(id[i], factors[i]);
55         //cout<<"factor: ";
56         //for (auto x:factors[i]) cout<<x<<' ';
57         //cout<<endl;
58     }
59     long long ans = 0;
60     long long sizeOfSet = 0;
61     while (T--) {
62         int t;
63         scanf("%d", &t);
64         --t;
65         if (inSet[t]) {
66             updateCnt(factors[t], -1);
67             sizeOfSet--;
68             ans -= sizeOfSet - howMany(id[t]);
69         } else {
70             ans += sizeOfSet - howMany(id[t]);
71             updateCnt(factors[t], 1);
72             sizeOfSet++;
73         }
74         inSet[t] = !inSet[t];
75         printf("%lld\n", ans);
76     }
77 }
View Code

H:

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 double n, a, p;
15 
16 int main() {
17     scanf("%lf%lf%lf", &n, &a, &p);
18     printf("%.8f\n", (a * p - a * (100.0 - p)) / 100.0 + n);
19     return 0;
20 }
View Code

I:

solver:lzh、zyh

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef pair<int, int> pii;
 5 #define ff first
 6 #define ss second
 7 const int mod = 1e9 + 7;
 8 
 9 ll mul(pii a, pii b, pii c) {
10     c.ff = c.ff - a.ff, c.ss = c.ss - a.ss;
11     a.ff = b.ff - a.ff, a.ss = b.ss - a.ss;
12     return 1ll * a.ff * c.ss - 1ll * a.ss * c.ff;
13 }
14 
15 pii a[1010], b[1010], c[1010];
16 int main() {
17     int s, r, m, n;
18     cin >> s >> r >> m;
19     for (int i = 1; i <= s; i++)
20         cin >> a[i].ff >> a[i].ss;
21     for (int i = 1; i <= r; i++)
22         cin >> b[i].ff >> b[i].ss;
23     for (int i = 1; i <= m; i++)
24         cin >> c[i].ff >> c[i].ss;
25     a[s + 1] = a[1], b[r + 1] = b[1], c[m + 1] = c[1];
26     cin >> n;
27     while (n--) {
28         pii x;
29         cin >> x.ff >> x.ss;
30         int gg = 0;
31         for (int i = 1; i <= s; i++)
32             if (mul(a[i], a[i + 1], x) < 0) {
33                 gg++;
34                 break;
35             }
36         if (!gg) {
37             cout << "Sheena\n";
38             continue;
39         }
40         gg = 0;
41         for (int i = 1; i <= r; i++)
42             if (mul(b[i], b[i + 1], x) < 0) {
43                 gg++;
44                 break;
45             }
46         if (!gg) {
47             cout << "Rose\n";
48             continue;
49         }
50         gg = 0;
51         for (int i = 1; i <= m; i++)
52             if (mul(c[i], c[i + 1], x) < 0) {
53                 gg++;
54                 break;
55             }
56         if (!gg) {
57             cout << "Maria\n";
58             continue;
59         }
60         cout << "Outside\n";
61     }
62 }
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 class FenwickTree {
15 private:
16     // 存储的信息类型
17     typedef int StoreType;
18     int n;
19     // num用于存储元素值,用于实现单点修改、区间查询
20     // diff用于存储差分,用于实现区间修改
21     vector<StoreType>num, diff;
22 public:
23     FenwickTree(): n(0) {}
24     FenwickTree(int _n) {
25         n = _n;
26         num.assign(n, 0);
27     }
28     // 单点修改
29     void add(int pos, int val) {
30         for (; pos < n; pos |= pos + 1) num[pos] += val;
31     }
32     // 查询区间[0..pos]的信息
33     StoreType sum(int pos) {
34         StoreType ret = 0;
35         for (; pos >= 0; pos = (pos & (pos + 1)) - 1) ret += num[pos];
36         return ret;
37     }
38     // 查询区间[l..r]的和
39     StoreType querySum(int l, int r) {
40         return sum(r) - sum(l - 1);
41     }
42     // 区间修改,给区间[l..r]里的元素都加上val
43     void intervalFix(int l, int r, int val) {
44         add(l, val); add(r + 1, -val);
45     }
46 };
47 
48 const int MAXN = 1e5 + 10;
49 int n, a[MAXN];
50 FenwickTree fwt(MAXN * 10);
51 
52 int main() {
53     scanf("%d", &n);
54     for (int i = 1; i <= n; i++) {
55         scanf("%d", &a[i]);
56         a[i]++;
57         printf("%d\n", n - (i - fwt.sum(a[i] - 1)) + 1);
58         fwt.add(a[i], 1);
59     }
60     return 0;
61 }
View Code

K:

solver:lzh

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef pair<int, int> pii;
 5 #define ff first
 6 #define ss second
 7 
 8 int dis[100010][3];
 9 struct edge {
10     int u, v, w;
11     edge(int _u = 0, int _v = 0, int _w = 0) {
12         u = _u, v = _v, w = _w;
13     }
14 } e[200010];
15 int head[100010], num = 0, vis[200010];
16 void addedge() {
17     int u, v, w;
18     cin >> u >> v >> w;
19     e[num] = edge(head[u], v, w);
20     head[u] = num++;
21     e[num] = edge(head[v], u, w);
22     head[v] = num++;
23 }
24 struct node {
25     int val, v, add;
26     node(int _val = 0, int _v = 0, int _add = 0) {
27         val = _val, v = _v;
28         add = _add;
29     }
30     bool operator<(const node &b) const {
31         return val > b.val;
32     }
33 };
34 int main() {
35     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
36     memset(dis, 0x3f, sizeof dis);
37     memset(head, -1, sizeof head);
38 
39     int n, m;
40     cin >> n >> m;
41     for (int i = 1; i <= m; i++) {
42         addedge();
43     }
44     priority_queue<node> q;
45     q.push(node{ 0, 1, 0 });
46     dis[1][0] = 0;
47     while (!q.empty()) {
48         node x = q.top();
49         q.pop();
50         for (int i = head[x.v]; i != -1; i = e[i].u) {
51             if ((vis[i] & x.add) == 0 && (vis[i ^ 1] & x.add) == 0) {
52                 vis[i] |= x.add, vis[i ^ 1] |= x.add;
53                 for (int j = 0; j < 3; j++) {
54                     int tmp = dis[e[i].v][j];
55                     tmp = min(tmp, dis[x.v][(j + 2) % 3] + e[i].w);
56                     if (e[i].v != n) {
57                         tmp = min(tmp, dis[x.v][j] + e[i].w * 3);
58                         tmp = min(tmp, dis[x.v][(j + 1) % 3] + e[i].w * 5);
59                     }
60                     if (e[i].v != n && dis[e[i].v][j] != tmp) {
61                         if ((vis[i] & 1) == 0)
62                             q.push(node{ dis[e[i].v][0], e[i].v, 1 });
63                         if ((vis[i] & 2) == 0)
64                             q.push(node{ dis[e[i].v][1], e[i].v, 2 });
65                         if ((vis[i] & 4) == 0)
66                             q.push(node{ dis[e[i].v][2], e[i].v, 4 });
67                     }
68                     dis[e[i].v][j] = tmp;
69                 }
70             }
71         }
72     }
73     pair<int, string> ans[10];
74     ans[1] = { dis[n][0], "me" };
75     ans[2] = { dis[n][1], "Gon" };
76     ans[3] = { dis[n][2], "Killua" };
77     sort(ans + 1, ans + 1 + 3);
78     for (int i = 1; i <= 3; i++)
79         cout << ans[i].ss << endl;
80 }
View Code

L:

solver:zyh、lzh、czq

读错题把队友坑了,锅++

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, int> point;
 4 vector<point> pts;
 5 bool check(point a, point b) {
 6     return (a.first < b.first && abs(a.first - b.first) + abs(a.second - b.second) <= 5);
 7 }
 8 vector<int> edges[200001];
 9 int dp[200001];
10 bool vis[200001];
11 bool reach0[200001];
12 map<int, map<int, int>> Map;
13 void dfs(int u) {
14     vis[u] = true;
15     dp[u] = 1;
16     for (auto v : edges[u]) {
17         if (!vis[v]) dfs(v);
18         if (reach0[v]) dp[u] = max(dp[u], dp[v] + 1);
19         reach0[u] |= reach0[v];
20     }
21 }
22 int main() {
23     int n, l;
24     scanf("%d%d", &n, &l);
25     pts.push_back(point(0, 0));
26     Map[0][0] = 0;
27     for (int i = 0; i < n; ++i) {
28         int x, y;
29         scanf("%d%d", &x, &y);
30         pts.push_back(point(x, y));
31         Map[x][y] = i + 1;
32     }
33     for (int i = 0; i <= n; ++i) {
34         int x = pts[i].first;
35         int y = pts[i].second;
36         for (int j = 1; j <= 5; ++j) {
37             if (Map.find(x + j) == Map.end()) continue;
38             auto iter = Map[x + j].lower_bound(y - (5 - j));
39             while (iter != Map[x + j].end() && iter->first <= y + 5 - j) {
40                 edges[iter->second].push_back(i);
41                 iter++;
42             }
43         }
44     }
45     reach0[0] = true;
46     for (int i = 0; i <= n; ++i)
47         if (!vis[i]) dfs(i);
48     point end = {l, 0};
49     int ans = 0;
50     for (int i = 0; i <= n; ++i) {
51         if (reach0[i] && check(pts[i], end)) ans = max(ans, dp[i] - 1);
52     }
53     printf("%d", ans);
54 }
View Code

 

posted @ 2020-03-15 18:58  JHSeng  阅读(334)  评论(0编辑  收藏  举报