CF Round#599(div2)

Round#599(div2)

概要

好多模拟题

B2. Character Swap (Hard Version)

题意:给两个串$s,t$,每次可以交换$s_i和t_j$,问能否让$s$和$t$相等
==思路:==
n很小,50

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from collections import *
for _ in range(int(input())):
n = int(input())
A = list(input())
B = list(input())
swap = []
ans = True
C = Counter(A+B)
for c in C:
ans = ans and (not(C[c] % 2))
if not ans:
print("No")
continue
for i in range(n):
if A[i] == B[i]:
continue
for j in range(i + 1,n):
if A[i] == A[j]:
swap.append((j+1,i+1))
B[i],A[j] = A[j],B[i]
break
if A[i] == B[j]:
swap.append((j+1,j+1))
swap.append((j+1,i+1))
B[i],B[j],A[j] = B[j],A[j],B[i]
break
print("Yes")
print(len(swap))
for i in swap:
print(str(i[0]) + " " + str(i[1]))

C. Tile Painting

求所有因数最大gcd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
// for(int i = 1;i <= 1000;i++){
// cout << i << " : ";
int n;
cin >> n;
vector<int>L;

int i = 2;
while(n != 1){
if(i*i > n){
L.push_back(n);
break;
}
if(n % i == 0){
L.push_back(i);
}
while(n % i == 0){
n/=i;
}
i++;
}
// if(L.size() == 0){
// cout << n << endl;
// }
if(L.size() >= 2){
cout << 1 << endl;
}
if(L.size() == 1){
cout << L[0] << endl;
}

}