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


相关文章
|
2月前
|
人工智能 测试技术 芯片
Codeforces Round 963 (Div. 2)
Codeforces Round 963 (Div. 2)
Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕。
50 0
Codeforces Round #178 (Div. 2)
在n条电线上有不同数量的鸟, Shaass开了m枪,每一枪打的是第xi条电线上的第yi只鸟,然后被打中的这只鸟左边的飞到第i-1条电线上,右边的飞到i+1条电线上,没有落脚点的鸟会飞走。
53 0
Codeforces Round #742 (Div. 2)
Codeforces Round #742 (Div. 2)
50 0
Codeforces Round 799 (Div. 4)
Codeforces Round 799 (Div. 4)
121 0
Codeforces Round #640 (Div. 4)
Codeforces Round #640 (Div. 4)
93 0