头条编程题 串珠 错在哪里 求大神
我的思路是 将每种颜色的珠子的位置几率下来 然后根据 距离来算
比如
5 2 3
3 1 2 3
0
2 2 3
1 2
1 3
第一种颜色true false false false false
第二种颜色true false true true false
第三种颜色true false true false true
Scanner scanner =new Scanner(System.in);
int count =0;
int n= scanner.nextInt();
int m =scanner.nextInt();
int c=scanner.nextInt();
boolean yanse[][]=new boolean [51][10001];
int i,j;
for ( i =1 ;i<=n;i++){
int num_i =scanner.nextInt();
if(num_i==0){
continue;
}
for (j=1 ;j<=num_i;j++){
int se= scanner.nextInt();
yanse[se][i]=true;
}
}
for(int i1 =1 ;i1<= c;i1++){
for (int j1=1 ;j1<=n;j1++){
System.out.print(yanse[i1][j1]+" ");
}
System.out.print("\n");
}
int sum =0;
int last =0;
for (int i1 =1 ;i1<=c;i1++){
for (int j1=1;j1<n;j1++){
for(int l1=j1+1;l1<=n;l1++){
if(yanse[i1][j1]&&yanse[i1][l1]){
sum=l1-j1;
if (sum==n-1)
{
sum=1;
}
if(sum<=m-1){
count++;
}
}
}
// if(yanse[i1][1]&&yanse[i1][n]){
// count=count+1;
// }
}
}
System.out.println(count);
}
