Codeforces Round 527 (Div. 3)

被自己菜哭::>_<::

A#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int a=n/m,b=n%m;
for(int i=1;i<=a;i++){
for(int i=1;i<=m;i++){
cout<<char('a'+i-1);
}
}
for(int i=1;i<=b;i++){
cout<<char('a'+i-1);
}
cout<<endl;
}
return 0;
}

B#

排序后统计相邻元素差值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
int ans=0;
for(int i=1;i<=n;i+=2){
ans+=a[i+1]-a[i];
}
cout<<ans<<endl;
return 0;
}

C#

利用两个长度为n-1的串把原串找出来,然后逐个判断。

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <bits/stdc++.h>
using namespace std;
char s[205][105];
int len[205],ps[205],markp[105],marks[105];
int main(){
//freopen("input.txt","r",stdin);
int n;
cin>>n;
int m=2*n-2;
int n1=0,n2=0;
for(int i=1;i<=m;i++){
cin>>s[i];
len[i]=strlen(s[i]);
if(len[i]==n-1&&n1==0)n1=i;
else if(len[i]==n-1&&n2==0)n2=i;
}
//printf("n1=%d,n2=%d\n",n1,n2);
int f2=1;
for(int i=1;i<n-1;i++){
if(s[n2][i]!=s[n1][i-1])f2=0;
}
int count=0;
for(int i=1;i<=m;i++){
int ff=1;
for(int j=0;j<len[i];j++){
if(s[i][j]!=s[n2][j]){
ff=0;
break;
}
}
if(ff)count++;
}
if(count<n-1)f2=0;
//printf("f2=%d\n",f2);
char *per,*sur;
per=s[n1],sur=s[n2];
if(f2)swap(per,sur);
for(int i=0;i<n-1;i++){
s[0][i]=per[i];
}
s[0][n-1]=sur[n-2];
len[0]=n;
//printf("s[0]=%s\n",s[0]);
int cs=0,cp=0;
for(int i=1;i<=m;i++){
//prefix
int flagp=1;
for(int j=0;j<len[i];j++){
if(s[i][j]!=s[0][j]){
flagp=0;
break;
}
}
//suffix
int flags=1;
for(int j=0;j<len[i];j++){
if(s[i][j]!=s[0][j+n-len[i]]){
flags=0;
break;
}
}
if(flagp==0){
ps[i]='S';
marks[len[i]]=1;
cs++;
}else if(flags==0){
ps[i]='P';
markp[len[i]]=1;
cp++;
}else ps[i]='A';
}
for(int i=1;i<=m;i++){
if(cp==n-1)break;
if(ps[i]=='A'&&!markp[len[i]]){
ps[i]='P';
cp++;
markp[len[i]]=1;
}
}
for(int i=1;i<=m;i++){
if(cs==n-1)break;
if(ps[i]=='A'&&!marks[len[i]]){
ps[i]='S';
marks[len[i]]=1;
cs++;
}
}
for(int i=1;i<=m;i++){
cout<<char(ps[i]);
}
cout<<endl;
return 0;
}

D1#

D2#

E#

F#

Avito Cool Challenge 2018

题目

A#

A. Definite Game

1
2
3
4
5
6
7
8
9
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==2)cout<<2<<endl;
else cout<<1<<endl;
return 0;
}

B#

B. Farewell Party

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
37
38
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N],b[N];
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
a[i]=n-a[i];
}
int f=1;
for(int i=1;i<=n;i++){
if(b[i]>0)continue;
b[i]=f;
int count=a[i]-1;
for(int j=i+1;j<=n;j++){
if(count==0)break;
if(b[j]>0)continue;
if(a[j]==a[i]){
b[j]=b[i];
count--;
}
}
if(count>0)f=0;
if(f==0)break;
f++;
}
if(f==0)puts("Impossible");
else{
puts("Possible");
for(int i=1;i<=n;i++){
printf("%d ",b[i]);
}
puts("");
}
return 0;
}

C#

C. Colorful Bricks
he found there are k bricks with a color different from the color of the brick on its left.
n个方块,m种颜色,存在k个方块与左边相邻方块颜色不同,求涂色方案数.
排列组合问题.

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
#include <bits/stdc++.h>
using namespace std;
const int N=2005;
const int MOD=998244353;
int Comn[N][N];
int Com(int n,int m){
for(int i=0;i<=n;i++){
Comn[i][0]=Comn[i][i]=1;
for(int j=1;j<i;j++){
Comn[i][j]=(1ll*Comn[i-1][j]+Comn[i-1][j-1])%MOD;
}
}
return Comn[n][m];
}
int Qpow(int x,int y){
int ans=1;
while(y){
if(y&1)ans=(1ll*ans*x)%MOD;
x=(1ll*x*x)%MOD;
y>>=1;
}
return ans;
}
int main(){
int n,m,k;
//cout<<Com(2,1)<<endl;
cin>>n>>m>>k;
//printf("Com=%d,Qpow=%d\n",Com(n-1,k),Qpow(m-1,k));
cout<<(1ll*Com(n-1,k)*m%MOD*Qpow(m-1,k))%MOD<<endl;
return 0;
}

D#

D. Maximum Distance

E#

E. Missing Numbers
依次尝试平方数。long long真是恶心。

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
37
38
39
40
41
42
43
#include <bits/stdc++.h>
#define check(x) ((long long)(sqrt(x))*(long long)(sqrt(x))==(x))
using namespace std;
const int N=100005;
const long long M=10000000000000ll;
long long a[N];
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n;
scanf("%d",&n);
for(int i=2;i<=n;i+=2){
scanf("%lld",&a[i]);
}
long long s=0,k=1,f=1;
for(int i=1;i<=n;i+=2){
while(1){
//printf("when k=%lld,s=%lld,check(%lld)=%d\n",k,s,k*k+a[i+1],check(k*k+a[i+1]));
if(k*k>s&&check(k*k+a[i+1])){
a[i]=k*k-s;
s=k*k+a[i+1];
k++;
break;
}
k++;
if(k>1000000){
f=0;
break;
}
}
if(f==0)break;
}
if(f==0)puts("No");
else{
puts("Yes");
for(int i=1;i<=n;i++){
printf("%lld ",a[i]);
}
puts("");
}
return 0;
}

F#

F. Tricky Interactor

G#

G. Mergesort Strikes Back

H#

H. Palindromic Magic