首页 > 代码库 > Codeforces 441C Valera and Tubes

Codeforces 441C Valera and Tubes

题目链接:Codeforces 441C Valera and Tubes

没看到r >= 2一直错。让前几个管子占用2个格子。最后一个把剩下的都占用了。假设问题有解。这样做一定有解。其它策略就不一定了(比方让某个管子占用了3个格子。而总共同拥有四个格子,两个管子)。

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x = 1, y = 1;
    bool flag = false;
    for(int i = 0; i < k - 1; i++)
    {
        printf("2");
        for(int j = 0; j < 2; j++)
        {
            if(!flag)
                printf(" %d %d", x, y++);
            else
                printf(" %d %d", x, y--);
            if(y > m)
            {
                flag = !flag;
                x++;
                y = m;
            }
            if(y < 1)
            {
                flag = !flag;
                x++;
                y = 1;
            }
        }
        puts("");
    }
    printf("%d", n * m - ((k - 1) * 2));
    while(x <= n)
    {
        if(!flag)
            printf(" %d %d", x, y++);
        else
            printf(" %d %d", x, y--);
        if(y > m)
        {
            flag = !flag;
            x++;
            y = m;
        }
        if(y < 1)
        {
            flag = !flag;
            x++;
            y = 1;
        }
    }
    puts("");
    return 0;
}


Codeforces 441C Valera and Tubes