Ejemplo n.º 1
0
static void testSolve1Flip() {
	// mover has 1 piece, and can flip 1 disk. Loses 3-61 = -58
	const u64 mover = 0x4;
	const int sq = 0;
	const u64 enemy = ~(mover | mask(sq));
	assertEquals(-58, solve1(mover, enemy, sq));

	assertEquals(64, solve1(0x0FFFFFFFFFFFFFFFULL, 0x70ULL<<56, 63));
}
Ejemplo n.º 2
0
static void testSolve1() {
	for (int sq = 0; sq<64; sq++) {
		// mover has no pieces, mover loses 0-63
		const u64 mover = 0;
		const u64 enemy = ~mask(sq);
		assertEquals(-63, solve1(mover, enemy, sq));
	}
	for (int sq = 0; sq<64; sq++) {
		// enemy has no pieces, mover wins 63-0
		const u64 enemy = 0;
		const u64 mover = ~mask(sq);
		assertEquals(63, solve1(mover, enemy, sq));
	}
	testSolve1Flip();
	testSolve1Pass();
}
Ejemplo n.º 3
0
int main()
{
	while(scanf("%d%d", &n, &m) == 2 && (n || m))
	{
		for(int i = 1; i <= n; i++) black[i].Read();
		for(int i = 1; i <= m; i++) white[i].Read();
		bool flag = 0;
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
			{
				if(black[i].x == white[j].x)
					flag |= solve1(black[i].x);
				if(black[i].y == white[j].y)
					flag |= solve2(black[i].y);
				else {
					int by = black[i].y, bx = black[i].x;
					int wy = white[j].y, wx = white[j].x;
					double k = 1.0 * (wy - by) / (wx - bx);
					double b = by - k * bx;
					flag |= solve3(k, b);
				}
			}
		if(flag) puts("YES"); else puts("NO");
	}
	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{

	int p[100][2];
	int rv ;
	
	int a = -1;
	int b = 1;

	rv = solve1(a, b, p,3000);		

	if(rv) {

		printf("Found %d solutions.\n", rv);
		
		for(int i = 0; i < rv; i++)
			printf("%d %d\n",p[i][0], p[i][1]);

	}
	else {

		printf("No integer solutions for a=%d b= %d .\n", a,b);

	}



	return(0);
}
Ejemplo n.º 5
0
void solve(int a) {
  int left = -1, right = -1;
  for(i=1;i<=n;i++) {
    if(p[i]%a==0) {
      q[i]=0;
    } else if ( (p[i] + 1) % a==0) {
      q[i] = B;
    }else if ( (p[i] - 1) % a==0) {
      q[i] = B;
    } else {
      q[i]=maxint;
      if(left < 0 )
        left = i;
      right = i;
    }
  }
  if(left<0) {
    solve1();
    return;
  }

  LD nowans=A;
  nowans*=(right-left+1);
  if(left>1) {
    nowans+=solveleft(left-1);
  }
  if(right<n) {
    nowans += solveright(right+1);
  }
  updateans(nowans);
}
Ejemplo n.º 6
0
static void testSolve1Pass() {
	// enemy has 1 piece, and can flip 1 disk. Mover wins 61-3 = 58, after a pass.
	const u64 mover = 0x4;
	const int sq = 0;
	const u64 enemy = ~(mover | mask(sq));
	assertEquals(-58, solve1(mover, enemy, sq));
}
Ejemplo n.º 7
0
int main(int argc, char **argv) {
    char *input_buf = NULL;
    size_t input_size = 0;
    int total_cases = 0;
    int cur_case = 0;

    getline(&input_buf, &input_size, stdin);
    total_cases = atoi(input_buf);
    free(input_buf);
    input_buf = NULL;

    while (cur_case < total_cases) {
        unsigned long arg1 = 0;
        unsigned long arg2 = 0;
        
        getline(&input_buf, &input_size, stdin);
        if (input_buf[0] == '1') {
            sscanf(input_buf, "1 %lu\n", &arg1);
            solve1(cur_case, arg1);
        } else if (input_buf[0] == '2') {
            sscanf(input_buf, "2 %lu %lu\n", &arg1, &arg2);
            solve2(cur_case, arg1, arg2);
        }

        free(input_buf);
        input_buf = NULL;
        cur_case++;
    }
    return 0;
}
Ejemplo n.º 8
0
int solve1(int input, int sum) {
     
    if (input == 0) {
        return sum;
    }
    else {
        sum = sum * input;
        return solve1(input - 1, sum);
    }
}
Ejemplo n.º 9
0
static void compareSolveNToSolve1(u64 mover, u64 enemy, int sq) {
	int result1 = solve1(mover, enemy, sq);
	const int resultN = solveNValue(-64, 64, mover, enemy);
	if (result1!=resultN) {
		printBoard(mover, enemy);
		std::cout << "black to move\n";
		std::cout << " Black: " << bitCount(mover) << "  White: " << bitCount(enemy) << "  Empty: " << bitCount(~(mover|enemy)) << "\n";
		solveNValue(-64, 64, mover, enemy);
	}
	assertEquals(result1, resultN);
}
int main(void) {
  int i;
  printf("Оцветяване на върховете по алгоритъм 1: \n");
  for (i = 0; i < n; i++) color[i] = 0;
  solve1();
  showColor();
  printf("Оцветяване на върховете по алгоритъм 2: \n");
  for (i = 0; i < n; i++) color[i] = 0;
  solve2();
  showColor();
  return 0;
}
Ejemplo n.º 11
0
Coloring Problem::solve(int exercise, int runs) const {
    if (runs < 1) {
        throw std::out_of_range("La cantidad de corridas debe ser mayor a 0");
    }

    switch (exercise) {
        case 1:
            for (auto i = 0; i < runs - 1; ++i) {
                solve1();
            }

            return solve1();
        case 2:
            for (auto i = 0; i < runs - 1; ++i) {
                solve2();
            }

            return solve2();
        case 3:
            for (auto i = 0; i < runs - 1; ++i) {
                solve3();
            }

            return solve3();
        case 4:
            for (auto i = 0; i < runs - 1; ++i) {
                solve4();
            }

            return solve4();
        case 5:
            for (auto i = 0; i < runs - 1; ++i) {
                solve5();
            }

            return solve5();
        default:
            throw std::out_of_range("Los ejercicios estan numerados del 1 al 5");
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
              char a[1001],b[1001];
              scanf("%s",a);
              scanf("%s",b);
              printf("%s\n",solve1(a,b)==solve2(a,b)?"YES":"NO");
    }
    return 0;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[])
{ 
	opt_proc(argc,argv);

	if (extraction_order==0)
		solve0();
	else if (extraction_order==1)
		solve1();
	else {
		fprintf(stderr,"extraction_order must be 0 or 1, abort\n");
		exit(-1);
	}

	return 0;
} 
Ejemplo n.º 14
0
int main(int argc, char** argv) {

	init();

	FILE* f;
	f=fopen("ref.txt","w"); solve1(); print(f); fclose(f);
	f=fopen("t.txt","w"); solve2(); print(f); fclose(f);
	int r=sys_exec("diff","-dur","ref.txt","t.txt",NULL);
	printf("\n\n");
	sys_exec("cat","t.txt",NULL);
	printf("\nCorrectness: %s\n",!r?"no differences":"FAILURE !!!");
	unlink("ref.txt"); unlink("t.txt");

	cleanup();
	return 0;
}
Ejemplo n.º 15
0
int main()
{
    //judge
    //
    int factorial[]      = {0, 1, 2, 3, 4, 5};
    int factorial_real[] = {1.1, 2.2, 3.3, 4.4, 5.5};
    for (int index = 0; index < (int)sizeof(factorial)/sizeof(factorial[0]); index++) {
        printf("result = %d\n", solve1(factorial[index], 1));
    }
    printf("\n");


    for (int index = 0; index < (int)sizeof(factorial)/sizeof(factorial[0]) ; index++) {
        //printf("result  = %d\n", solve2(factorial[index]));
    }

    return 0;
}
Ejemplo n.º 16
0
int solve2(double *coeff, double *roots)
{
    double a, b, c;
    double disc, b_over_2a, c_over_a;

    a = coeff[2], b = coeff[1], c = coeff[0];
    if (AEQ0(a))
	return solve1(coeff, roots);
    b_over_2a = b / (2 * a);
    c_over_a = c / a;

    disc = b_over_2a * b_over_2a - c_over_a;
    if (disc < 0)
	return 0;
    else if (disc == 0) {
	roots[0] = -b_over_2a;
	return 1;
    } else {
	roots[0] = -b_over_2a + sqrt(disc);
	roots[1] = -2 * b_over_2a - roots[0];
	return 2;
    }
}
Ejemplo n.º 17
0
void solve2(Vector& x)
{
   const double K1 = 10000./2.54, K2= 10000./254., K3 = 10000./2.54;
   double c1, c2, c3, c4, y, z, km1, km3, km;

//based on many assumptions

   c1 = x(19) + x(20);
   c2 = x(13) + x(14) + x(27);
   c3 = x(26) + x(27);
   c4 = x(3) + x(20) + x(14) + x(27);

   if (c2 < 0) {
      c2 = 0;
      x(13) = x(14) = x(27) = 0;
   }
   if (c4 < 0)
   {
      c4 = 0;
      x(3) = x(14) = x(20) = x(27) = 0;
   }
                                                                                                              
   km1 = K1/(x(19) + K1);
   km3 = K3/(x(26) + K3);
   km = K2*km3/km1;
                              
   z = solve1( c2 + c4 + km, c2*c4);
   y = c4 - z;

   x(3) = km1*y;
   x(20) = y - x(3);
   x(19) = c1 - x(20);
   x(13) = c2 - z;
   x(14) = km3*z;
   x(27) = z - x(14);
   x(26) = c3 - x(27);
}