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.

Sample test(s)
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:

#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 100000
#define ll long long
using 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 long
using 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;
}




这样就非常easy懂了。由于printf是从右向左编译的,cnt++在,处实现自增。

Valera and Tubes的更多相关文章

  1. Codeforces 441C Valera and Tubes

    题目链接:Codeforces 441C Valera and Tubes 没看到r >= 2一直错.让前几个管子占用2个格子.最后一个把剩下的都占用了.假设问题有解.这样做一定有解.其它策略就 ...

  2. codeforces Round #252 (Div. 2) C - Valera and Tubes

    贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...

  3. codeforces C. Valera and Tubes

    http://codeforces.com/contest/441/problem/C 题意:有n×m个方格,然后把这些方格分成k部分,每个部分内的方格的坐标满足|xi - xi + 1| + |yi ...

  4. codeforces 441C. Valera and Tubes 解题报告

    题目链接:http://codeforces.com/problemset/problem/441/C 题目意思:将n * m 的矩阵分成 k 堆.每堆是由一些坐标点(x, y)组成的.每堆里面至少由 ...

  5. Codeforces441C_Valera and Tubes(暴力)

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

  6. Codeforces Round 252 (Div. 2)

    layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  7. 怎样用Zbrush中的Curves Tubes创建手指

    之前我们已经能够初步完成了模型的人体躯干,今天的Zbrush教程将继续使用Curves Tubes创建手指,实现更细致的塑形.文章内容仅以fisker老师讲述为例,您也可以按照自己的想法,跟着老师的步 ...

  8. CF 369C . Valera and Elections tree dfs 好题

    C. Valera and Elections   The city Valera lives in is going to hold elections to the city Parliament ...

  9. [Codeforces Round #237 (Div. 2)] A. Valera and X

    A. Valera and X time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. Winsock在Windows下的编程教程(C语言)(图文并茂,超长教程)

    https://www.0xaa55.com/forum.php?mod=viewthread&tid=378&extra=page%3D2

  2. springmvc-3.2-jsr303解决服务端验证问题

    从以前的验证:Stringutils.isEmpty....到struts的验证:xxxvalidate 现在使用jsr303使之更加简单  依赖hibernate-validator-4.xx.ja ...

  3. log4j的使用及参考

    log4j.properties 使用 一.参数意义说明 输出级别的种类 ERROR.WARN.INFO.DEBUG ERROR 为严重错误 主要是程序的错误 WARN 为一般警告,比如session ...

  4. Dreamer2.1 发布 新增将Bean解析成xml和json

    一个上午,增加两个功能 1.直接将对象解析成XML 2.将对象解析成JSON 对象可以是数组,可以是集合,也可以是单个对象 源码和jar下载地址:http://pan.baidu.com/share/ ...

  5. poi操作officePOI操作excel中的数据格式(日期类型)

    7.3.3 POI中Excel文件Cell的类型 在读取每一个Cell的值的时候,通过getCellType方法获得当前Cell的类型,在Excel中Cell有6种类型,如表7-3所示. 表7-3 C ...

  6. C++:互斥量C++实现,内存调试,自动锁

    /*互斥量C++实现+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ class CMutex { public: C ...

  7. 08-UIKit(UITableTableViewCell、自定义Cell、xcode调试)

    目录: 1. UITableTableViewCell 2. tag技术 3. 自定义Cell 4. 用nib文件构造自定义的静态表 5. TableView数据模型总结 6. Xcode代码调试 & ...

  8. 在 Windows Azure 网站上使用 Django、Python 和 MySQL:创建博客应用程序

    编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Sunitha Muthukrishna 撰写. 根据您编写的应用程序,Windows Azure 网站上的基本Python 堆 ...

  9. css sprites 图片精灵自动生成 插件

    grunt-spritesmith https://www.npmjs.com/package/grunt-spritesmith

  10. cloudflare的新waf,用Lua实现的

    我们使用nginx贯穿了我们的网络,做前线web服务,代理,流量过滤.在某些情况下,我们已经扩充了nginx上我们自己的模块的核心C代码,但近期我们做了一个重大举措,与nginx结合使用lua 差点儿 ...