Educational Codeforces Round 65 (Rated for Div. 2)
A
# include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
int a=-1;
string s;
scanf("%d",&n);
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='8'){
a=i;
break;
}
}
if(a==-1){
printf("NO\n");
}else{
if((n-a)>=11){
printf("YES\n");
}else{
printf("NO\n");
}
}
}
return 0;
}
B
# include <bits/stdc++.h>
using namespace std;
int f[50];
int ff[7][7];
int main()
{
int a1,a2,a3,a4,a5,a6;
int aa,bb,cc,dd;
int a[7]={0,4,8,15,16,23,42};
for(int i=1;i<=6;i++){
for(int j=1;j<=6;j++){
ff[i][j]=a[i]*a[j];
}
}
// for(int i=1;i<=6;i++){
// for(int j=1;j<=6;j++){
// cout<<ff[i][j]<<" ";
// }
// cout<<endl;
// }
int i1=1,j1=2;
printf("? %d %d\n",i1,j1);fflush(stdout);
scanf("%d",&aa);
int i2=2,j2=3;
printf("? %d %d\n",i2,j2);fflush(stdout);
scanf("%d",&bb);
int i3=3,j3=4;
printf("? %d %d\n",i3,j3);fflush(stdout);
scanf("%d",&cc);
int i4=4,j4=5;
printf("? %d %d\n",i4,j4);fflush(stdout);
scanf("%d",&dd);
int e,g,h,y,x,v;
int flag1=0,flag2=0;
for(int ni=1;ni<=6;ni++){
for(int nj=(ni+1);nj<=6;nj++){
//cout<<"@"<<endl;
if(ff[ni][nj]==aa){
e=a[ni];
g=a[nj];
flag1=1;
break;
}
}
if(flag1) break;
}
for(int ni=1;ni<=6;ni++){
for(int nj=(ni+1);nj<=6;nj++){
if(ff[ni][nj]==bb){
h=a[ni];
y=a[nj];
flag2=1;
break;
}
}
if(flag2) break;
}
if(e==h){
a2=e;
}else if(e==y){
a2=e;
}
if(g==h){
a2=g;
}else if(g==y){
a2=g;
}
f[a2]=1;
a1=aa/a2;
f[a1]=1;
a3=bb/a2;
f[a3]=1;
a4=cc/a3;
f[a4]=1;
a5=dd/a4;
f[a5]=1;
for(int i=1;i<=6;i++){
if(f[a[i]]==0) a6=a[i];
}
printf("! %d %d %d %d %d %d\n",a1,a2,a3,a4,a5,a6);fflush(stdout);
return 0;
}
C
#include <bits/stdc++.h>
using namespace std;
int pr[500005];
int sum[500005];
int finds(int x)
{
if(x == pr[x]) return x;
pr[x] = finds(pr[x]);
sum[pr[x]] += sum[x];
return pr[x];
}
inline void ini(int x, int y)
{
if(x == y) return ;
sum[x] += sum[y];sum[y] = 0;
pr[y] = x;
}
int main()
{
int n, m, k;
scanf("%d%d", &n, &m);
for(register int i = 1 ; i <= n ; i ++){pr[i] = i;sum[i] = 1;}
int x, y;
while(m--)
{
scanf("%d", &k); if(!k) continue;
scanf("%d", &x);
for(int i = 2 ; i <= k ; i ++)
{
scanf("%d", &y);
ini(finds(x), finds(y));
}
}
for(register int i = 1 ; i <= n ; i ++) printf("%d ",sum[finds(i)]);
return 0;
}
相关文章
- 10-10Codeforces Round #648 (Div. 2) F - Swaps Again 思维
- 10-10Codeforces Round #286 (Div. 2) B. Mr. Kitayuta's Colorful Graph (二维并查集)
- 10-10Codeforces Round #358 (Div. 2) Alyona and the Tree
- 10-10Codeforces Round #746 (Div. 2)
- 10-10Codeforces Round #746 (Div. 2)
- 10-10Codeforces Round #746 (Div. 2)
- 10-10Codeforces Round #622 (Div. 2) A. Fast Food Restaurant
- 10-10Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大
- 10-10Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)
- 10-10Educational Codeforces Round 115 (Rated for Div. 2)