Exemplo n.º 1
0
int main()
{
    freopen("numar4.in","r",stdin);
    freopen("numar4.out","w",stdout);
    scanf("%d %d",&ni,&nz);
    int i;
    a[0]=ni+nz;
    for(i=ni+nz; i>0; --i) scanf("%d",&a[i]);
    b[0]=nz+1; b[nz+1]=1;
    for(i=nz;i!=0 && a[1]%2==0;) {
        imp(a,2);
        imp(b,2);
        --i;
    }
    for(i=nz;i!=0 && a[1]%5==0;) {
        imp(a,5);
        imp(b,5);
        --i;
    }
    printf("%d\n",a[0]);
    afis(a);
    printf("\n%d\n",b[0]);
    afis(b);
    return 0;
}
Exemplo n.º 2
0
int main()
{
	long i, j, mid;
	scanf("%ld %ld", &N, &S);
	OS = S;
	if (S & 1) S = 10000L;
	S /= 2;
	S = min(S, 9 * N - S);
	memset(l1, 0, sizeof(l1)); memset(l2, 0, sizeof(l2));
	for (i = 0; i < 10; i++) l1[i][0] = l1[i][1] = 1;
	if (S >= 0)
	for (i = 2; i <= N; i++)
	{
		l2[0][0] = l2[0][1] = 1; poz = 0;
		mid = 9 * i / 2 + (i & 1);
		for (j = 1; j <= mid; j++)
		{
			memcpy(l2[j], l2[j - 1], sizeof(l2[j - 1]));
			add(l2[j], l1[min(j, 9 * (i - 1) - j)]);
			if (j >= 10)
				sub(l2[j], l1[poz++]);
		}
		memcpy(l1, l2, sizeof(l2));
		memset(l2, 0, sizeof(l2));
	}
	if (S >= 0)
		mul(l1[S], l1[S], sol);
	if (S < 0) sol[0] = 1;
	if (OS == 2 && N >= 10) sol[0] = 1, sol[1] = 0;
	afis(sol);
	return 0;
}
Exemplo n.º 3
0
void solve_b() {
    mat[1][1][1] = c[1];

    for (int niv = 1; niv < nrn; ++niv) {
        for (int i = 1; i <= niv + 1; ++i)
            for (int j = 1; j <= niv + 1; ++j)
                mat[niv + 1][i][j] = INF;

        for (int i = 1; i <= niv; ++i)
            for (int j = 1; j <= niv; ++j) {
                mat[niv + 1][i][j] = min(mat[niv + 1][i][j], mat[niv][i][j] + c[ind[niv + 1][i][j]]);
                mat[niv + 1][i + 1][j] = min(mat[niv + 1][i + 1][j], mat[niv][i][j] + c[ind[niv + 1][i + 1][j]]);
                mat[niv + 1][i][j + 1] = min(mat[niv + 1][i][j + 1], mat[niv][i][j] + c[ind[niv + 1][i][j + 1]]);
                mat[niv + 1][i + 1][j + 1] = min(mat[niv + 1][i + 1][j + 1], mat[niv][i][j] + c[ind[niv + 1][i + 1][j + 1]]);
            }
    }

    int rez = INF, linr = 0, colr = 0;

    for (int i = 1; i <= nrn; ++i)
        for (int j = 1; j <= nrn; ++j)
            if (mat[nrn][i][j] < rez) {
                rez = mat[nrn][i][j];
                linr = i;
                colr = j;
            }

    printf("%d\n", rez);

    afis(nrn, linr, colr);
}
Exemplo n.º 4
0
int main()
{
    citire();
    dinamica();
    afis();
    return 0;
}
Exemplo n.º 5
0
int main() {
    assert(freopen("pscpld.in", "r", stdin));
    assert(freopen("pscpld.out", "w", stdout));

    assert(scanf("%s", s + 1) == 1);
    
    edit();

    solve();

    afis();

    return 0;
}
Exemplo n.º 6
0
void	ft_print_comb2(void)
{
	int a;
	int b;

	a = 0;
	while (a <= 99)
	{
		b = a + 1;
		while (b <= 99)
		{
			afis(a);
			ft_putchar(' ');
			afis(b);
			if (a != 98)
			{
				ft_putchar(',');
				ft_putchar(' ');
			}
			b++;
		}
		a++;
	}
}
Exemplo n.º 7
0
void afis(int niv, int i, int j) {
    if (niv == 0)
        return;

    int newi = 0, newj = 0;
    for (int d = 0; d < 4; ++d) {
        newi = i + dx[d];
        newj = j + dy[d];

        if (newi > 0 && newi < niv && newj > 0 && newj < niv && mat[niv][i][j] - mat[niv - 1][newi][newj] == c[ind[niv][i][j]]) {
            afis(niv - 1, newi, newj);
            break;
        }
    }

    printf("%d ", ind[niv][i][j]);
}