A - QQ solver
题意: 给定一个由三个字符组成的字符串S,其按照顺序是一个a和b之间(包括1和9)的整数以及字符x的串联:axb。
找到a和b的乘积。
思路: 字符串模拟即可,记得字符转整数时要减去 - ‘0’
AC代码
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define xx first
#define yy second
#define sz size
typedef long long LL;
typedef pair<int , int> PII;
typedef pair<LL , LL> PLL;
const int N = 100010, INF = 0x3f3f3f3f, Mod = 998244353;
char s[N];
void solved()
{
for(int i = 1; i <= 3; i ++)
{
cin >> s[i];
}
int a = s[1] - '0';
int b = s[3] - '0';
cout << a * b;
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//int t;
//cin >> t;
while(t -- )
{
solved();
}
return 0;
}
B - Caesar Cipher
题意: Takahashi有一个由小写英文字母组成的字符串S。
他将对这个字符串执行以下操作,只执行一次:
首先,选择一个非负整数K。
然后,将S中的每个字符向右移动K个位置(具体见下文)。
移动规则如下:
a向右移动1个位置变成b;
b向右移动1个位置变成c;
c向右移动1个位置变成d;
⋯
y向右移动1个位置变成z;
z向右移动1个位置变成a。
例如,b向右移动4个位置变成f,y向右移动3个位置变成b。
给定一个字符串T,请确定Takahashi是否可以通过上述操作使得S等于T。
要解决这个问题,我们需要进行逆向操作来验证字符串T是否可以通过右移得到字符串S。
思路:计算出变化次数k:k = (s1[0]-s2[0] + 26)%26。遍历字符串,两两做差,若次数不为k即为false
AC代码
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define xx first
#define yy second
#define sz size
typedef long long LL;
typedef pair<int , int> PII;
typedef pair<LL , LL> PLL;
const int N = 100010, INF = 0x3f3f3f3f, Mod = 998244353;
string s1, s2;
int ans[N];
void solved()
{
cin >> s1 >> s2;
int n = s1.size();
//int b = s2.size();
for(int i = 0; i < n; i ++)
{
ans[i] = s1[i] - s2[i];
if(ans[i] < 0) ans[i] += 26;
}
for(int i = 0; i < n; i ++)
{
if(i == n - 1) break;
if(ans[i] != ans[i + 1])
{
cout << "No";
return ;
}
}
cout << "Yes";
return ;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//int t;
//cin >> t;
while(t -- )
{
solved();
}
return 0;
}
C - Graph Isomorphism
题意:Takahashi和Aoki各自有一种玩具,通过将M根绳索连接到N个球上制作而成。
在Takahashi的玩具中,球的编号为1、2、…、N,第i根绳索将球A[i]和B[i]连接起来。
类似地,在Aoki的玩具中,球的编号也是1、2、…、N,第i根绳索将球C[i]和D[i]连接起来。
在每个玩具中,没有绳索将一个球与自己连接,并且没有两个球被两根或更多不同的绳索连接。
Snuke想知道这两个玩具是否具有相同的形状。
这里所说的形状相同指的是存在满足以下条件的排列P。
P是(1, 2, …, N)的一个排列。
对于位于1和N之间(包括1和N)的每对整数i和j,满足以下条件。
如果Takahashi玩具中的球i和j由一根绳索连接,则Aoki玩具中的球P[i]和P[j]也由一根绳索连接。
如果这两个玩具具有相同的形状,则输出Yes;否则输出No。
思路:使用了STL里面的next_permutation函数,即求序列的下一个排列,下一个排列是字典序大一号的排列,把点进行映射,如果存在一组映射与原数据不冲突即为答案。寻找可能解时使用了全排列,因为如果有解必然是排列的一种。数据很小暴力dfs即可。
AC代码
#include <bits/stdc++.h>
using namespace std;
int p[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
int n, m, g[10][10], h[10][10];
int main()
{
cin >> n >> m;
for(int i = 1, x, y; i <= m; i ++) cin >> x >> y, g[x][y] = g[y][x] = true;
for(int i = 1, x, y; i <= m; i ++) cin >> x >> y, h[x][y] = h[y][x] = true;
do
{
int f = 1;
for(int i = 1; i <= n && f; i ++)
for(int j = 1; j <= n && f; j ++)
if(g[i][j] ^ h[p[i]][p[j]]) f = 0;
if(f)
{
puts("Yes");
return 0;
}
} while(next_permutation(p + 1, p + n + 1));
puts("No");
}