20140222

#include<stdio.h>
void main()
{
    int n, m, i, p, k, w[100];
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++)
        w[i] = i + 1;
    i = 0;
    k = 1;
    p = 0;
    while (p < n - 1)
    {
        if (w[i] == -1)
        {
            i = (i + 1) % n;
            continue;
        }
        if (k == m)
        {
            w[i] = -1;
            p++;
            k = 0;
        }
        k++;
        i = (i + 1) % n;
    }
    for (i = 0; i < n;i++)
    if (w[i] != -1)
    {
        printf("%d\n", w[i]);
        break;
    }
}

while (!(a == R || b == R || c == R))
{
    if (!b)
    {
        a -= bv;
        b = bv;
    }
    else if (c == cv)
    {
        a += cv;
        c = 0;
    }
    else if (b > cv - c)
    {
        b -= cv - c;
        c = cv;
    }
    else
    {
        c += b;
        b = 0;
    }
    printf(a, b, c);
}

#include<stdio.h>
void main()
{
    int a, b, c, bv, cv, R, n;
    scanf("%d%d%d", &a, &bv, &cv);
    R = a / 2;//平分
    b = c = 0;
    n = 0;
    while (!(a == R || b == R || c == R))
    {
        if (!b)
        if (a < bv)
        {
            n = -1;
            break;
        }
        else//无法倒满b,则不能分
        {
            a -= bv;
            b = bv;
        }
        else if (c == cv)//c倒满a
        {
            a += cv;
            c = 0;
        }
        else if (b > cv - c)//b能倒满c
        {
            b -= cv - c;
            c = cv;
        }
        else//b不能倒满c
        {
            c += b;
            b = 0;
        }
        n++;
        printf("%d  %d  %d\n", a, b, c);
    }
    printf("%d\n", n);
}

 

posted @ 2014-02-22 20:04  yuanqi  阅读(217)  评论(2编辑  收藏  举报