Codeforces Round #252(Div. 2) 441C. Valera and Tubes 构造

C. Valera and Tubes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns – starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).

Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:

  • r ≥ 2;
  • for any integer i (1 ≤ i ≤ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
  • each table cell, which belongs to the tube, must occur exactly once in the sequence.

Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:

  • no pair of tubes has common cells;
  • each cell of the table belongs to some tube.

Help Valera to arrange k tubes on his rectangle table in a fancy manner.

Input

The first line contains three space-separated integers n, m, k (2 ≤ n, m ≤ 300; 2 ≤ 2k ≤ n·m) — the number of rows, the number of columns and the number of tubes, correspondingly.

Output

Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integersxi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).

If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.

Examples
input
3 3 3
output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
input
2 3 1
output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note

Picture for the first sample:

Picture for the second sample:


题意:

给一个n*m的地图,用k个管道全部覆盖,要求:每个管道长度不小于2,四联通,且每个格子只能被一个管道覆盖到,输出方案。


题解:

构造。

从左上角开始,向右铺,然后掉头向左铺,来回循环即可,前k-1个管道的长度都是2,然后第k个管道把剩下的都铺完就好了。

/****************
*PID:441c div2
*Auth:Jonariguez
*****************
*/
#define lson k*2,l,m
#define rson k*2+1,m+1,r
#define rep(i,s,e) for(i=(s);i<=(e);i++)
#define For(j,s,e) For(j=(s);j<(e);j++)
#define sc(x) scanf("%d",&x)
#define In(x) scanf("%I64d",&x)
#define pf(x) printf("%d",x)
#define pfn(x) printf("%d\n",(x))
#define Pf(x) printf("%I64d",(x))
#define Pfn(x) printf("%I64d\n",(x))
#define Pc printf(" ")
#define PY puts("YES")
#define PN puts("NO")
#include <stdio.h>
#include <string.h>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef int Ll;
Ll quick_pow(Ll a,Ll b,Ll MOD){a%=MOD;Ll res=1;while(b){if(b&1)res=(res*a)%MOD;b/=2;a=(a*a)%MOD;}return res;}

const int maxn=300+10;
int a[maxn][maxn];

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

    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/u013068502/article/details/51067681