Valera and Tubes

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 integers xi1, 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

题意:给定n*m个格子和k和管道,要求每个管道连接的格子不能少于两个。

思路:前k-1个管子贪心的选择给两个格子就够了,剩下的格子全给第k个管子。

#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define fi first
#define se second
#define u1 (u<<1)
#define u2 (u<<1|1)
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define PLL pair<long long,long long>
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scl(a) scanf("%lld",&a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define pb(a) push_back(a)
#define mst(a,b) memset(a, b, sizeof a)
using namespace std;
int n,m,k;
bool st[310][310];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
vector<PII> ans;
void dfs(int x,int y,int deep,int sum)//deep表示管子序号,sum用于前k-1个管子到两个格子时换管子
{
    st[x][y]=true;
    ans.push_back({x,y});
    if(deep==k)
    {
        for(int i=0;i<4;i++)
       {
        int nx=x+dx[i],ny=y+dy[i];
        if(!st[nx][ny]&&nx>=1&&nx<=n&&ny>=1&&ny<=m) dfs(x+dx[i],y+dy[i],deep,sum+1);
       }
    }
    else if(sum==2)
    {
        for(int i=0;i<4;i++)
       {
           int nx=x+dx[i],ny=y+dy[i];
        if(!st[nx][ny]&&nx>=1&&nx<=n&&ny>=1&&ny<=m) dfs(x+dx[i],y+dy[i],deep+1,1);
       }
    }
    else
    {
        for(int i=0;i<4;i++)
       {
        int nx=x+dx[i],ny=y+dy[i];
        if(!st[nx][ny]&&nx>=1&&nx<=n&&ny>=1&&ny<=m) dfs(x+dx[i],y+dy[i],deep,2);
       }
    }
}

void solve()
{

   cin>>n>>m>>k;
   dfs(1,1,1,1);
   for(int i=1,j=0;i<=k;i++)
   {
       if(i==k){
          cout<<ans.size()-j<<' ';
          while(j<ans.size()){
            cout<<ans[j].first<<' '<<ans[j++].second<<' ';
          }
          cout<<endl;
       }
       else{
          cout<<2<<' ';
          cout<<ans[j].first<<' '<<ans[j++].second<<' ';
          cout<<ans[j].first<<' '<<ans[j++].second<<' '<<endl;
       }
   }
}

int main()
{
    int t=1;
   // scd(t);
    while(t--) solve();
    return 0;
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值