Codeforces Round #786 (Div. 3)

简介: 笔记

A Number Transformation


10.png

样例#1

输入#1

3

3 75

100 100

42 13

输出#1

2 5

3 1

0 0

void solve() {
  int x, y; cin >> x >> y;
  if(y % x != 0) {
    cout << 0 << ' ' << 0 << endl;
  } else {
    cout << 1 << ' ' << y / x << endl;
  }
}

B Dictionary


题 意 : 规 则 : a b = 1 , a c = 2 , . . . , a z = 25 , b a = 26 , b c = 27 , . . . , z y = 650


思路:打表O(1)输出即可。见代码...


样例#1


输入#1

7

ab

ac

az

ba

bc

zx

zy


输出#1


1

2

25

26

27

649

650

map<string, int> mp;
void init() {
  int cnt = 1;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      if(i == j) continue;
      char a = i + 'a';
      char b = j + 'a';
      string x = "";
      x += a, x += b;
      mp[x] = cnt++;
    }
  }
}
void solve() {
  string s; cin >> s;
  cout << mp[s] << endl;
}
signed main() {
  IOS int _ = 1;
  init();
  cin >> _;
  while(_--) { solve(); }
  return 0;
}

C Infinite Replacement


题意:给定母串S(全由字符'a'组成),替换串T。现可以将S中一个字符'a'替换为整个T,问能变成多少种不同串,可以替换任意次。


输出最多能变成的不同串的个数,能变无限多则输出-1


思路:


发现这有三种情况:

11.png

样例#1

输入#1

3

aaaa

a

aa

abc

a

b

输出#1

1

-1

2

void solve() {
  string s; cin >> s;
  string t; cin >> t;
  int n = s.sz, m = t.sz;
  int res = -1;
  if(m == 1) {
    if(t == "a") res = 1;
    else res = (1ll << n);
  } else {
    if(t.find("a") != -1) res = -1;
    else res = (1ll << n);
  }
  cout << res << endl;
}

D A-B-C Sort


12.png

样例#1

输入#1

3

4

3 1 5 3

3

3 2 1

1

7331

输出#1

YES

NO

YES

int a[N];
void solve() {
  int n; cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i >= 1; i -= 2) {
    if(a[i] < a[i - 1]) {
      swap(a[i], a[i - 1]);
    }
  }
  bool o = true;
  for (int i = 0; i < n - 1; i++) {
    if(a[i] > a[i + 1]) o = false;
  }
  puts(o ? "YES" : "NO");
}

E Breaking the Wall


13.png

int a[N];
void solve()
{
  int n; cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int res = 0x3f3f3f3f;
  for (int i = 1; i < n; i++) {
    int x = a[i], y = a[i + 1];
    if(x < y) swap(x, y);
    int cnt = min(x - y, (x + 1) / 2);
    x -= 2 * cnt;
    y -= cnt;
    if(x > 0 && y > 0) cnt += (x + y - 1) / 3 + 1;
    res = min(res, cnt);
  }
  for (int i = 1; i < n - 1; i++) {
    int cnt = 0;
    int x = a[i], y = a[i + 2];
    if(x < y) swap(x, y);
    res = min(res, y + (x - y + 1) / 2);
  }
  sort(a + 1, a + 1 + n);
  res = min(res, (a[1] + 1) / 2 + (a[2] + 1) / 2);
  cout << res << endl;
}

F Desktop Rearrangement


G Remove Directed Edges


相关文章
|
1月前
|
人工智能 测试技术 C++
Codeforces Round 962 (Div. 3)
Codeforces Round 962 (Div. 3)
|
5月前
Codeforces Round #729 (Div. 2)
【6月更文挑战第4天】在这两个编程问题中,B. Plus and Multiply 要求判断通过加法和乘法操作数组是否能形成目标数 `n`。思路是形如 `x^a + yb = n` 的表达式,如果满足则能构造。C. Strange Function 关注的是找到最小正整数 `x` 使得 `x` 不是 `i` 的因子,计算这些值的和模 `10^9+7`。对于每个 `i`,偶数时 `f(i)` 是 3,奇数时是 2,利用因子与最大公约数计算周期性求和。
32 1
Codeforces Round #742 (Div. 2)
Codeforces Round #742 (Div. 2)
46 0
|
机器学习/深度学习 人工智能
Codeforces Round 889 (Div. 2)
Codeforces Round 889 (Div. 2)
160 0
|
机器学习/深度学习 Go
codeforces round 885 (div. 2)
codeforces round 885 (div. 2)
97 0
|
人工智能 索引
Codeforces Round 806 (Div. 4)
Codeforces Round 806 (Div. 4)A~G
111 0
|
人工智能 BI
Codeforces Round 827 (Div. 4)
Codeforces Round 827 (Div. 4)A~G题解
101 0
Codeforces Round #640 (Div. 4)
Codeforces Round #640 (Div. 4)
88 0