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; }
void solve( int * aInput, int aInputCount, int aOrder ) { int i = 0; int sMaxValue = 0; int sMaxDepth = 0; std::stack<int> sAnswer; memset( gArray, 0x00, MAX_LENGTH * sizeof(int) ); /* init table */ for ( i = 0; i < aInputCount; i++ ) { gArray[aInput[i]] = i+1; if ( sMaxValue < aInput[i] ) { sMaxValue = aInput[i]; } } for ( i = 1; i < sMaxValue+1; i++ ) { if ( gArray[i] == 0 ) { continue; } solve2( i, sMaxValue+1, 1, &sMaxDepth, &aOrder, &sAnswer ); if ( aOrder == 0 ) { break; } } printResult( sMaxDepth, &sAnswer ); }
int main(){ int T; scanf("%d",&T); while(T-->0){ scanf("%lld",&N); if(N<2){ printf("%d\n",0); } else if(N==2){ printf("%d\n",5); } else{ printf("%lld\n",solve2()); //printResult(); // printf("result : %lld,%lld,%lld,%lld\n",ra,rb,rc,rd); } } }
int main(int argc, const char *argv[]) { /*freopen("10272.txt", "r", stdin);*/ setbuf(stdout, NULL); int T; scanf("%d", &T); while (T--) { reset(); scanf("%d", &noOfPegs); limit = noOfPegs; int i; for(i = 0; i < noOfPegs; i++) { solve2(); } coutAns(); } return 0; }
int solve3(double *coeff, double *roots) { double a, b, c, d; int rootn, i; double p, q, disc, b_over_3a, c_over_a, d_over_a; double r, theta, temp, alpha, beta; a = coeff[3], b = coeff[2], c = coeff[1], d = coeff[0]; if (AEQ0(a)) return solve2(coeff, roots); b_over_3a = b / (3 * a); c_over_a = c / a; d_over_a = d / a; p = b_over_3a * b_over_3a; q = 2 * b_over_3a * p - b_over_3a * c_over_a + d_over_a; p = c_over_a / 3 - p; disc = q * q + 4 * p * p * p; if (disc < 0) { r = .5 * sqrt(-disc + q * q); theta = atan2(sqrt(-disc), -q); temp = 2 * cbrt(r); roots[0] = temp * cos(theta / 3); roots[1] = temp * cos((theta + M_PI + M_PI) / 3); roots[2] = temp * cos((theta - M_PI - M_PI) / 3); rootn = 3; } else { alpha = .5 * (sqrt(disc) - q); beta = -q - alpha; roots[0] = cbrt(alpha) + cbrt(beta); if (disc > 0) rootn = 1; else roots[1] = roots[2] = -.5 * roots[0], rootn = 3; } for (i = 0; i < rootn; i++) roots[i] -= b_over_3a; return rootn; }
int main() { int n; // solve1(); solve2(); while (scanf("%d", &n) == 1) { if (!n) break; else { if (n % 10 == 1 && n % 100 != 11) printf("The %dst humble number is %d.\n", n, data[n]); else if (n % 10 == 2 && n % 100 != 12) printf("The %dnd humble number is %d.\n", n, data[n]); else if (n % 10 == 3 && n % 100 != 13) printf("The %drd humble number is %d.\n", n, data[n]); else printf("The %dth humble number is %d.\n", n, data[n]); } } return 0; }
/* * Runs the main program */ int main(int argc, char *argv[]) { int N, C, ans = 0; int max_weights; int weight[MAX], value[MAX]; struct timeval tstart, tend; double t1, t2; thread_count = 6; N = strtol(argv[1], NULL, 10); C = strtol(argv[2], NULL, 10); max_weights = strtol(argv[3], NULL, 10); create_problem(N, max_weights, weight, value); gettimeofday(&tstart, NULL); ans = solve(N, C, weight, value); gettimeofday(&tend, NULL); t1 = check_time(tstart, tend); printf("Solver finished in %lf seconds.\n", t1/1000000.0); gettimeofday(&tstart, NULL); solve2(N, C, weight, value); gettimeofday(&tend, NULL); t2 = check_time(tstart, tend); double s_scaling = t2 / (thread_count * t1); printf("Solver finished in %lf seconds.\n", t2/1000000.0); printf("Answer: %d \n", ans); printf("Strong Scaling: %lf\n", s_scaling); return 0; }
static void testSolve2Done() { const u64 white = 0; const u64 black = ~0x3ULL; assertEquals(62, solve2(-64, 64, black, white, 0, 1)); assertEquals(-62, solve2(-64, 64, white, black, 0, 1)); }
bool Jeu::solveRecursive() { solve2(0,0); return true; }