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

Educational Codeforces Round 56

题目

A#

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

B#

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
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
char s[1005];
int c[305]={0};
cin>>s;
int len=strlen(s);
for(int i=0;i<len;i++){
c[s[i]]++;
}
int count=0;
for(int i=0;i<305;i++){
if(c[i]>0)count++;
}
if(count==1)cout<<"-1\n";
else{
for(int i=0;i<305;i++){
if(c[i]>0){
for(int j=0;j<c[i];j++){
cout<<char(i);
}
}
}
cout<<endl;
}
}
return 0;
}

C#

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
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
const long long INF=(long long)(1e18+1);
long long a[N];
int main(){
//cout<<(long long)1e18<<endl;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int n;
cin>>n;
int n2=n/2;
for(int i=1;i<=n2;i++){
cin>>a[n-i+1];
//printf("a[%d]=%lld\n",n-i+1,a[n-i+1]);
}
a[0]=-1;a[n+1]=INF;
for(int i=1;i<=n2;i++){
if(a[i]>=a[i-1]&&a[n-i+1]<=a[n-i+2])continue;
long long temp=max(a[i-1]-a[i],a[n-i+1]-a[n-i+2]);
a[i]+=temp;
a[n-i+1]-=temp;
if(a[i]>a[n-i+1])swap(a[i],a[n-i+1]);
}
for(int i=1;i<=n;i++){
cout<<a[i]<<' ';
}
cout<<endl;
return 0;
}

D#

memset改成手动清零

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
#include <bits/stdc++.h>
using namespace std;
const int N=300005;
const int M=998244353;
vector<int> G[N];
int vis[N],col[N],deg[N];
int cnt[2];
int kpow(int x,int y){
int ans=1;
while(y){
if(y&1)ans=(1ll*ans*x)%M;
x=(1ll*x*x)%M;
y>>=1;
}
return ans;
}
int dfs(int x,int p=0){
//printf("when dfs(%d):\n",x);
vis[x]=1;
col[x]=p;
cnt[p]++;
for(auto i:G[x]){
int f=1;
if(vis[i]&&col[i]==col[x])return 0;
if(!vis[i])f=dfs(i,!p);
if(f==0)return 0;
}
return 1;
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
G[i].clear();
vis[i]=col[i]=deg[i]=0;
}
//memset(vis,0,sizeof(vis));
//memset(col,0,sizeof(col));
//memset(deg,0,sizeof(deg));
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
deg[u]++,deg[v]++;
}
int f=1,ans=1;
for(int i=1;i<=n;i++){
if(deg[i]==0){
ans=(ans*3ll)%M;
continue;
}
if(!vis[i]){
cnt[0]=cnt[1]=0;
if(!dfs(i))f=0;
else{
//printf("count[0]=%d,count[1]=%d\n",cnt[0],cnt[1]);
ans=(1ll*ans*(kpow(2,cnt[0])+kpow(2,cnt[1])))%M;
}
}
if(f==0)break;
}
if(f==0)puts("0");
else printf("%d\n",ans);
}
return 0;
}

E#

F#

G#

Minecraft Server Tootal World

Minecraft Server Tootal World

服务器已不再维护,以下信息可能已过时。

版本:1.13.2
地址:120.79.171.171:23333
模式:原版生存
难度:4

阅读更多