A:

Solved.

签。

AtCoder Grand Contest 029 Solution_字符串AtCoder Grand Contest 029 Solution_结点_02
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3  
 4 #define ll long long
 5 #define N 200010
 6 char s[N];
 7  
 8 int main()
 9 {
10     while (scanf("%s", s + 1) != EOF)
11     {
12         ll res = 0;
13         int len = strlen(s + 1); int last = len;
14         for (int i = len; i >= 1; --i)
15         {
16             if (s[i] == 'B') 
17             {
18                 res += last - i;
19                 --last;
20             }
21         }
22         printf("%lld\n", res);
23     }
24     return 0;
25 }
View Code

 

B:

Solved.

签。

AtCoder Grand Contest 029 Solution_字符串AtCoder Grand Contest 029 Solution_结点_02
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3  
 4 #define N 200010
 5 int n, a[N], Bit[50];
 6 unordered_map <int, int> mp; 
 7  
 8 int main()
 9 {
10     Bit[0] = 1;
11     for (int i = 1; i <= 30; ++i) Bit[i] = Bit[i - 1] << 1;
12     while (scanf("%d", &n) != EOF)
13     {
14         mp.clear();
15         for (int i = 1; i <= n; ++i)  
16         {
17             scanf("%d", a + i);
18             ++mp[a[i]];
19         }
20         sort(a + 1, a + 1 + n);
21         int res = 0; 
22         for (int i = n; i >= 1; --i) 
23         {
24             int pos = upper_bound(Bit, Bit + 30, a[i]) - Bit;
25             //cout << a[i] << " " << Bit[pos] << endl;
26             if (pos >= 31 || mp[a[i]] == 0) continue;
27             int tar = Bit[pos] - a[i]; 
28             if ((tar != a[i] && mp[tar]) || (tar == a[i] && mp[tar] > 1)) 
29             {
30                 ++res; 
31                 --mp[tar];
32             }    
33             --mp[a[i]]; 
34         }
35         printf("%d\n", res);
36     }
37     return 0;
38 }
View Code

 

C:

Unsolved.

题意:
一共有n个字符串,给出每个字符串的长度,要求构造这些字符串,使得$S_1 < S_2 < \cdots < S_n$

这里的小于重载为字典序

 

D:

Solved.

题意:

在一个棋盘上,A只能向下走,B只能向走

刚开始一个棋子位于(1, 1)位置,有些地方有障碍物,如果有障碍物或到边界就不能走
A想要总步数最多,B想要总步数最少,双方都采用最优策略,问A最后最多能走多少步

思路:

因为A只能向下走,而且只要下面没有障碍物,他一定会向下走

那我们维护B最远能走到那里,然后一层一层往下看,如果最远能走的地方大于等于当前层某个障碍物的横坐标

那么就可以在这层让A停下来

AtCoder Grand Contest 029 Solution_字符串AtCoder Grand Contest 029 Solution_结点_02
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3  
 4 #define N 200010
 5 int h, w, n;
 6 vector <int> v[N];
 7  
 8 int main()
 9 {
10     while (scanf("%d%d", &h, &w) != EOF)
11     {
12         scanf("%d", &n); 
13         int res = h; 
14         for (int i = 1; i <= h; ++i) v[i].clear();     
15         for (int i = 1, x, y; i <= n; ++i)
16         {
17             scanf("%d%d", &x, &y);
18             v[x].push_back(y);
19         }
20         int far = 1; 
21         for (int i = 2; i <= h; ++i) 
22         {
23             if (v[i].empty()) 
24             {
25                 ++far;
26                 continue;
27             }
28             sort(v[i].begin(), v[i].end());
29             if (v[i][0] <= far) 
30             {
31                 res = i - 1;
32                 break;
33             }
34             bool flag = true; 
35             for (auto it : v[i]) if (it == far + 1)
36                 flag = false;
37             far += flag; 
38         }
39         printf("%d\n", res); 
40     }
41     return 0;
42 }
View Code

 

E:

Unsolved.

题意:

在一棵树上,有一个人迷路了,在某个地方,他要回到编号为1的结点

他采用的策略是每次都选择相邻的编号最小的点去走,走不通就回溯,求最后走到结点1的步数为多少

注意输出n - 1个数,分别为当前处于第$i点,要回到1的步数$

 

F:

Unsolved.