Valera and Tubes

來源:互聯網
上載者:User

C. Valera and Tubestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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.

Sample test(s)input
3 3 3
output
3 1 1 1 2 1 33 2 1 2 2 2 33 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:

#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 100000#define ll long longusing namespace std;int n, m, k, cnt, col, row;int x[MAXN], y[MAXN];int main(void){    int i,j,n,m,k;    cin>>n>>m>>k;    col=1;row=1;cnt=0;    int  dir=0;    while(cnt<n*m)    {      //  printf("%d %d %d..\n",row,col,cnt);        if(dir==0)        {            if(col<=m)            {                x[cnt]=row;                y[cnt]=col;               // printf("[%d %d]\n",x[cnt],y[cnt]);                col++;            }            else            {                x[cnt]=row+1;                y[cnt]=col-1;                row++;col-=2;                dir=1;            }        }        else if(dir==1)        {            if(col>=1)            {                x[cnt]=row;                y[cnt]=col;                col--;            }            else if(col==0)            {                x[cnt]=row+1;                y[cnt]=col+1;                row++;col=2;                dir=0;            }        }        cnt++;    }    cnt=0;    for(i=0;i<k-1;i++)    {        printf("2 ");        printf("%d %d ",x[cnt],y[cnt]);        cnt++;        printf("%d %d\n",x[cnt],y[cnt]);        cnt++;    }    printf("%d ",n*m-cnt);    for(;cnt<n*m;cnt++)        printf("%d %d ",x[cnt],y[cnt]);    cout<<endl;    return 0;}

另外 有個比較奇怪的現象,如果把cnt++放在printf裡面、測試如下:

<pre name="code" class="cpp">#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 100000#define ll long longusing namespace std;int n, m, k, cnt, col, row;int x[MAXN], y[MAXN];int main(void){    int i,j,n,m,k;    cin>>n>>m>>k;    col=1;row=1;cnt=0;    int  dir=0;    while(cnt<n*m)    {      //  printf("%d %d %d..\n",row,col,cnt);        if(dir==0)        {            if(col<=m)            {                x[cnt]=row;                y[cnt]=col;               // printf("[%d %d]\n",x[cnt],y[cnt]);                col++;            }            else            {                x[cnt]=row+1;                y[cnt]=col-1;                row++;col-=2;                dir=1;            }        }        else if(dir==1)        {            if(col>=1)            {                x[cnt]=row;                y[cnt]=col;                col--;            }            else if(col==0)            {                x[cnt]=row+1;                y[cnt]=col+1;                row++;col=2;                dir=0;            }        }        cnt++;    }    cnt=0;     for(;cnt<n*m;cnt++)        printf("%d %d %d\n",x[cnt],y[cnt],cnt);    cnt=0;    for(i=0;i<k-1;i++)    {        printf("2 ");        printf("[%d] %d [%d] %d [%d] ",cnt,x[cnt],cnt,y[cnt++],cnt);        printf("[%d] %d [%d] %d [%d]\n",cnt,x[cnt],cnt,y[cnt++],cnt);    }    printf("%d ",n*m-cnt);    for(;cnt<n*m;cnt++)        printf("%d %d ",x[cnt],y[cnt]);    cout<<endl;    return 0;}





這樣就很容易懂了。因為printf是從右向左編譯的,cnt++在,處實現自增。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.