其他分享
首页 > 其他分享> > Codeforces Round #786 (Div. 3) - 题解

Codeforces Round #786 (Div. 3) - 题解

作者:互联网

A. Number Transformation

题目传送门

翻译

Solution

送分题。

首先判无解。考虑到 \(b^a\) 必定为正整数,所以如果 \(x \nmid y\),则无解。

如果有解,则说明 \(\frac{y}{x}\) 为正整数。那么我们构造 \(a = 1, b = \frac{y}{x}\) 就好啦。

Code

#include <bits/stdc++.h>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-' ? -1 : f), ch = getchar();
    while (isdigit(ch)) x = (x<<3) + (x<<1) + ch - '0', ch = getchar();
    return x*f;
}

int t, x, y; 

signed main() {
    t = read();
    while (t--) {
	x = read(), y = read();
	if (y%x) printf("0 0\n");
	else printf("1 %d\n", y/x);
    }
}

B. Dictionary

题目传送门

翻译

Solution

我们知道,以 \(a\) 打头的单词有 \(25\) 个,以 \(b\) 打头的单词也有 \(25\) 个,...,以 \(z\) 打头的单词也有 \(25\) 个。

那么,第一个字母与 \(s\) 不同且排在 \(s\) 前面的单词就有 \((\)$s_0 - $' \(\texttt{a}\) ' \() \ \times \ 25\) 个。

接下来我们求出第一个字母与 \(s\) 相同且排在 \(s\) 前面的单词个数即可。

问题也就迎刃而解了。

Code

#include <bits/stdc++.h>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-' ? -1 : f), ch = getchar();
    while (isdigit(ch)) x = (x<<3) + (x<<1) + ch - '0', ch = getchar();
    return x*f;
}

string s;
int t;

signed main() {
    t = read();
    while (t--) {
	cin >> s;
	if (s[0] > s[1])
	    printf("%d\n", (s[0]-'a')*25+s[1]-'a'+1);
	else printf("%d\n", (s[0]-'a')*25+s[1]-'a');
    }
}


C. Infinite Replacement

题目传送门

翻译

Solution

首先思考什么时候答案为无穷大。

考虑这样一种情况,\(t\) 中包含了字符 '\(\texttt{a}\)':

其余情况下,根据子集相关知识,答案显然为 \(2^k\),其中 \(k\) 为 \(s\) 的长度。

注意要开 long long

Code

#include <bits/stdc++.h>
#define int long long 
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-' ? -1 : f), ch = getchar();
    while (isdigit(ch)) x = (x<<3) + (x<<1) + ch - '0', ch = getchar();
    return x*f;
}

const int L = 2e5 + 5;
string s, t;
bool f;
int q; 

signed main() {
    q = read();
    while (q--) {
	cin >> s >> t;
	f = 0;
	for (int i = 0; i < t.size(); i++)
	    if (t[i] == 'a') f = 1;
			
	if (f) {
	    if (t.size() == 1) 
		puts("1");
	    else puts("-1");
	} else
	    printf("%lld\n", (1LL<<s.size()));
    }
}


D. A-B-C Sort

作者咕了,下次一定更。


E. Breaking the Wall

作者咕了,下次一定更。

标签:25,786,ch,int,题解,texttt,单词,leq,Div
来源: https://www.cnblogs.com/SparkleZH-Blog/p/16218009.html