Ejemplo n.º 1
0
count_black(struct rbnode *x)
{
  int nleft, nright;
  
  if (x==RBNULL)
    return(1);
  
  nleft=count_black(x->left);
  nright=count_black(x->right);
  
  if (nleft==-1 || nright==-1)
    return(-1);
  
  if (nleft != nright)
    {
      fprintf(stderr, "Black count not equal on left & right, x=%ld", x);
      return(-1);
    }
  
  if (x->colour == BLACK)
    {
      nleft++;
    }
  
  return(nleft);
}
Ejemplo n.º 2
0
Archivo: 297.cpp Proyecto: waiwai444/oj
int count_black(quad_tree *tree_node1, quad_tree *tree_node2)
{
	if(tree_node1->type == 'f')
		return tree_node1->width*tree_node1->width;
	if(tree_node2->type == 'f')
		return tree_node2->width*tree_node2->width;
	if(tree_node1->type == 'e')
		return tree_node2->black_count;
	if(tree_node2->type == 'e')
		return tree_node1->black_count;
	int sum = count_black(tree_node1->rt, tree_node2->rt);
	sum += count_black(tree_node1->lt, tree_node2->lt);
	sum += count_black(tree_node1->lb, tree_node2->lb);
	sum += count_black(tree_node1->rb, tree_node2->rb);
	return sum;
}
Ejemplo n.º 3
0
Archivo: 297.cpp Proyecto: waiwai444/oj
int main()
{
	int tc, bc;
	char str1[1500], str2[1500];
	scanf("%d", &tc);
	while(tc--)
	{
		scanf("%s%s", str1, str2);
		create_tree(tree1, str1, 0, 32, &bc);
		create_tree(tree2, str2, 0, 32, &bc);
		printf("There are %d black pixels.\n", count_black(tree1, tree2));
	}
	return 0;
}
Ejemplo n.º 4
0
int rb_check(struct rbnode *rootp) {
  if (rootp==NULL || rootp==RBNULL)
    return(0);
  
  if (rootp->up!=RBNULL) {
    fprintf(stderr, "Root up pointer not RBNULL");
    dumptree(rootp, 0);
    return(1);
  }
  
  if (rb_check1(rootp)) {
    dumptree(rootp, 0);
    return(1);
  }

  if (count_black(rootp)==-1)
    {
      dumptree(rootp, 0);
      return(-1);
    }
  
  return(0);
}