比赛链接:https://codeforces.com/contest/1419

https://codeforces.com/contest/1419/problems

A. Digit Game

Codeforces Round #671 (Div. 2) (A - B、D1题) - 图1

Example

input

  1. 4
  2. 1
  3. 2
  4. 1
  5. 3
  6. 3
  7. 102
  8. 4
  9. 2069

output

  1. 2
  2. 1
  3. 1
  4. 2

题意:

Raze and Breach参加比赛,给定一个 Codeforces Round #671 (Div. 2) (A - B、D1题) - 图2 位的数字(从高位到低位 Codeforces Round #671 (Div. 2) (A - B、D1题) - 图3~ Codeforces Round #671 (Div. 2) (A - B、D1题) - 图4),Raze只能标记奇数位的数字,而Breach只能标记偶数的值,如果存在当仅剩一个未标记的数字时,比赛结束。 如果最后一位数字是奇数,则Raze获胜,否则Breach获胜。

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int _, n; string s;
  4. void solve() {
  5. cin >> n >> s;
  6. bool f1 = false, f2 = false;
  7. for (int i = 0; i < n; i += 2)if ((s[i] - '0') % 2 == 1)f1 = true;
  8. for (int i = 1; i < n; i += 2)if ((s[i] - '0') % 2 == 0)f2 = true;
  9. if (n % 2) puts(f1 ? "1" : "2");
  10. else puts(f2 ? "2" : "1");
  11. }
  12. int main() {
  13. //freopen("in.txt", "r", stdin);
  14. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  15. cin >> _; while (_--)solve();
  16. }

B. Stairs

Codeforces Round #671 (Div. 2) (A - B、D1题) - 图5

Example

input

  1. 4
  2. 1
  3. 8
  4. 6
  5. 1000000000000000000

output

  1. 1
  2. 2
  3. 1
  4. 30

思路:

待补

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll _, n, ans, now;
  5. void solve() {
  6. cin >> n;
  7. ans = 2, now = 0;
  8. while ((ans - 1) * ans / 2 <= n)n -= (ans - 1) * ans / 2, now++, ans *= 2;
  9. cout << now << endl;
  10. }
  11. int main() {
  12. //freopen("in.txt", "r", stdin);
  13. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  14. cin >> _; while (_--)solve();
  15. }

D1. Sage’s Birthday (easy version)

https://codeforces.com/problemset/problem/1419/D1

现在有 n 个数,对 a[] 重新排序,使得好数最多

好数的定义:在数组中比相邻的两个数都小,则称为好数,当然数组最左边和最右边的数不能称之为好数

可以保证在数组 a 中,所有的数都是不相同的

观察好数定义,要在数组中相邻的两个数都小,利用样例举例

  1. 5
  2. 1 2 3 4 5 (这个时候即使乱序也没事,需要sort
  3. 如果我们先从2开始放入b[],间隔2
  4. 会得到:
  5. 2 x 4 x 5
  6. 然后再从1开始:
  7. 2 1 4 3 5
  8. b[]符合好数定义
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e5;
  4. int n; long long a[N + 10], b[2 * N + 1];
  5. int main() {
  6. //freopen("in.txt", "r", stdin);
  7. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  8. cin >> n;
  9. for (int i = 1; i <= n; ++i)cin >> a[i];
  10. sort(a + 1, a + 1 + n); int idx = 1;
  11. cout << (n - 1) / 2 << endl;
  12. for (int i = 2; i <= n; i += 2)b[i] = a[idx++];
  13. for (int i = 1; i <= n; i += 2)b[i] = a[idx++];
  14. for (int i = 1; i < idx; ++i)cout << b[i] << " ";
  15. cout << endl;
  16. }