コード例 #1
0
ファイル: checker1.c プロジェクト: chevalun/acm-icpc
/*
 * Calculate number of ways to place checkers
 * on each row of the board starting at row i and going to row n.
 */
void
nway(i, lim) {
    int j;
 
    if(i == n) {
	nsol++;
	if (n > 6 && row[0] < n/2) nsol++;
	if (nprinted++ < 3) solution();
	return;
    }
 
    for(j=0; j<lim; j++){
	if(!col[j] && !updiag[i+j] && !downdiag[i-j+MAXN]){
	    row[i] = j;
 
	    col[j]++;
	    updiag[i+j]++;
	    downdiag[i-j+MAXN]++;
 
	    nway(i+1,n);
 
	    col[j]--;
	    updiag[i+j]--;
	    downdiag[i-j+MAXN]--;
	}
    }
}
コード例 #2
0
ファイル: CanvasTest.cpp プロジェクト: MIPS/external-skia
// Check that NWayCanvas does NOT try to manage the lifetime of its sub-canvases
DEF_TEST(NWayCanvas, r) {
    const int w = 10;
    const int h = 10;
    bool life[2];
    {
        LifeLineCanvas c0(w, h, &life[0]);
        REPORTER_ASSERT(r, life[0]);
    }
    REPORTER_ASSERT(r, !life[0]);


    std::unique_ptr<SkCanvas> c0 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[0]));
    std::unique_ptr<SkCanvas> c1 = std::unique_ptr<SkCanvas>(new LifeLineCanvas(w, h, &life[1]));
    REPORTER_ASSERT(r, life[0]);
    REPORTER_ASSERT(r, life[1]);

    {
        SkNWayCanvas nway(w, h);
        nway.addCanvas(c0.get());
        nway.addCanvas(c1.get());
        REPORTER_ASSERT(r, life[0]);
        REPORTER_ASSERT(r, life[1]);
    }
    // Now assert that the death of the nway has NOT also killed the sub-canvases
    REPORTER_ASSERT(r, life[0]);
    REPORTER_ASSERT(r, life[1]);
}
コード例 #3
0
ファイル: checker1.c プロジェクト: chevalun/acm-icpc
main(void) {
    FILE *fin = fopen("checker.in", "r");
    fout = fopen("checker.out", "w");
    fscanf(stdin, "%d", &n);
    nway(0, n>6?(n+1)/2:n);
    fprintf(fout, "%d\n", nsol);
    exit (0);
}