A Number Transformation
样例#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
思路:
发现这有三种情况:
样例#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
样例#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
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; }