예제 #1
0
파일: test_u64bits.c 프로젝트: herumi/walb
int main()
{
	int i;
	int bit_ary[64];
	u64 bits;

	init_random();

	/* Initialize */
	for (i = 0; i < 63; i++) {
		bit_ary[i] = get_random(2);
	}
	for (i = 0; i < 63; i++) {
		if (bit_ary[i]) {
			set_bit_u64(i, &bits);
		} else {
			clear_bit_u64(i, &bits);
		}
	}
	ASSERT(is_the_same(bit_ary, &bits));

	/* Randomly set and check. */
	for (i = 0; i < 100000; i++) {

		int j = get_random(64);

		if (get_random(2)) {
			bit_ary[j] = 1;
			set_bit_u64(j, &bits);
		} else {
			bit_ary[j] = 0;
			clear_bit_u64(j, &bits);
		}

		ASSERT(is_the_same(bit_ary, &bits));
	}

	return 0;
}
예제 #2
0
int main() {
  int n, m, x, y;
  char cmd;
  scanf(" %d %d", &n, &m);
  init_union(n);
  for(int i=0; i<m; ++i) {
    scanf(" %c %d %d", &cmd, &x, &y);
    if (cmd=='C') {
      printf("%s\n", is_the_same(x, y)?"S":"N");
    }
    else {
      make_union(x, y);
    }
  }
  return 0;
}
예제 #3
0
static int there_is_implicit_predicate( Coeff_p tuple_ptr,
					int tr,
					int pl)
 {/* Init there_is_implicit_predicate */
  int comp = GET_PLACE_COMPONENTS(pl);
  int ret_value = FALSE;
  int i,non_null;
 
  for(i = 0 ; i < comp ; i++)
   {/* Per ogni componente del dominio del posto */
    non_null = get_non_null_coefficient(tuple_ptr,tr,pl,i);
    if(is_the_same(tuple_ptr,tr,pl,i,non_null))
     {
      ret_value = TRUE;
      break;
     }
   }/* Per ogni componente del dominio del posto */
  return(ret_value);
 }/* End there_is_implicit_predicate */
예제 #4
0
파일: calc.cpp 프로젝트: amogil/icfpc2013
bool gen_trees()
{
	for(int i = 0; i < 3; i++)
	{
		trees[cnt].type = i;
		eval(i);
		t[1].push_back(cnt);
		cnt++;
	}
	first[1] = 0;
	last[1] = cnt;
	for(int size = 2; size < 21; size++)
	{
		first[size] = cnt;
		for(int type = 3; type < 8; type++)
		{
			if (!good_op[type])
				continue;
			for(int i = first[size-1]; i < last[size-1]; i++)
			{
				trees[cnt].type = type;
				trees[cnt].lhs = i;
				if (eval(cnt))
					cnt++;
				if (is_the_same())
					return true;
				if (test_timer())
					return false;
				//if (cnt >= max_size - 2)
				//return false;
			}
		}
		for(int type = 8; type < 12; type++)
		{
			if (!good_op[type])
				continue;
			for(int left_size = 1; left_size < size - 1; left_size++)
			{
				int right_size = size - 1 - left_size;
				if (left_size < right_size)
					continue;
				for(int i = first[left_size]; i < last[left_size]; i++)
					for(int j = first[right_size]; j < last[right_size] && j <= i; j++)
					{
						trees[cnt].type = type;
						trees[cnt].lhs = i;
						trees[cnt].rhs = j;
						if (eval(cnt))
							cnt++;
						if (is_the_same())
							return true;
						if (test_timer())
							return false;
						//if (cnt >= max_size - 2)
						//return false;
					}
			}
		}
		for(int type = 12; type < 13; type++)
		{
			if (!good_op[type])
				continue;
			for(int left_size = 1; left_size < size - 2; left_size++)
				for(int right_size = 1; right_size + left_size < size - 2; right_size++)
				{
					int last_size = size - 1 - left_size - right_size;
					{
						for(int i = first[left_size]; i < last[left_size]; i++)
							for(int j = first[right_size]; j < last[right_size]; j++)
								for(int k = first[last_size]; k < last[last_size]; k++)
								{
									trees[cnt].type = type;
									trees[cnt].lhs = i;
									trees[cnt].rhs = j;
									trees[cnt].if_cond = k;
									if (eval(cnt))
										cnt++;
									if (is_the_same())
										return true;
									if (test_timer())
										return false;
									//if (cnt >= max_size - 2)
									//return false;
								}
					}
				}
		}
		last[size] = cnt;
		printf("%d %d\n", size, last[size] - first[size]);
		if (last[size] - first[size] > 0)
		{
			int best_if = build_if();
			if (best_if != -1)
				return best_if;
		}
		fflush(stdout);
	}
	return false;
}