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. Chapter 5.依赖倒转原则

    抽象不应该依赖谢姐,细节应该依赖于抽象:针对接口编程,不要对实现编程.例如电脑内的内存坏了不会影响到其它模块,而且什么品牌都可以插入内存插槽,而不仅限于某个品牌的内存条. A.高层模块不应该依赖底层模 ...

  2. TensorFlow文本与序列的深度模型

    TensorFlow深度学习笔记 文本与序列的深度模型 Deep Models for Text and Sequence 转载请注明作者:梦里风林Github工程地址:https://github. ...

  3. 几个BCB例子

    http://blog.163.com/tab_98/blog/static/11924097201511274543737/

  4. Main方法的执行过程(转)

    要运行一个 main 方法 , 首先要知道 main 方法所在的 Class, 在命令行中指定这个 Class 名 Class Lava{ Private int speed = 4; Void fl ...

  5. 用 Python 测试框架简化测试

    用 Python 测试框架简化测试 摘要:本文将向您介绍了三种流行 Python 测试框架(zope.testing,py.test,nose)的基本特性,并讨论新一代的测试风格. 最近出现了行业级的 ...

  6. Eclipse中JBOSS5.1无法启动的问题解决办法

    今天在Eclipse中启动JBoss 5.1时遇到这样的一个错误: …… ERROR [AbstractKernelController] Error installing to Instantiat ...

  7. JSP中使用cookie存储中文

    今天看J2EE的时候,看见书上讲到使用cookie保存信息的时,看到书上举得例子都是英文的键值对,我就想中文是不是一样呢?试了一下果然不一样.废话不多说,直接上代码: 比如说有addCookie.js ...

  8. Netty开发实现高性能的RPC服务器

    Netty开发实现高性能的RPC服务器 RPC(Remote Procedure Call Protocol)远程过程调用协议,它是一种通过网络,从远程计算机程序上请求服务,而不必了解底层网络技术的协 ...

  9. Java网络编程:利用Java mail包发送电子邮件

    下面代码是利用Java mail包封装了一个发送邮件的类 import java.io.File; import java.util.ArrayList; import java.util.Date; ...

  10. linux下的软件包安装

    linux下安装软件包有两种方法:源文件编译安装(source)和 rpm 安装. 1.源文件包安装的通用方法. 一般安装源代码的程序你得要看它的README,一般在它的目录下都有的. 01.配置: ...