Valera and Tubes
1 second
256 megabytes
standard input
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.
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.
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.
3 3 3
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
2 3 1
6 1 1 1 2 1 3 2 3 2 2 2 1
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的更多相关文章
- Codeforces 441C Valera and Tubes
题目链接:Codeforces 441C Valera and Tubes 没看到r >= 2一直错.让前几个管子占用2个格子.最后一个把剩下的都占用了.假设问题有解.这样做一定有解.其它策略就 ...
- codeforces Round #252 (Div. 2) C - Valera and Tubes
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完 由于数据比较小,可以先打表 #include <iostream> #include <vector> #i ...
- codeforces C. Valera and Tubes
http://codeforces.com/contest/441/problem/C 题意:有n×m个方格,然后把这些方格分成k部分,每个部分内的方格的坐标满足|xi - xi + 1| + |yi ...
- codeforces 441C. Valera and Tubes 解题报告
题目链接:http://codeforces.com/problemset/problem/441/C 题目意思:将n * m 的矩阵分成 k 堆.每堆是由一些坐标点(x, y)组成的.每堆里面至少由 ...
- Codeforces441C_Valera and Tubes(暴力)
Valera and Tubes time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round 252 (Div. 2)
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- 怎样用Zbrush中的Curves Tubes创建手指
之前我们已经能够初步完成了模型的人体躯干,今天的Zbrush教程将继续使用Curves Tubes创建手指,实现更细致的塑形.文章内容仅以fisker老师讲述为例,您也可以按照自己的想法,跟着老师的步 ...
- 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 ...
- [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 ...
随机推荐
- Python基础1:一些小知识汇总
一.#!usr/bin/env python 脚本语言的第一行,指定执行脚本的解释器. #!/usr/bin/python 是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python解释器 ...
- 数据库中操作XML(openXML)
最近公司项目需要在数据库中操作XML,因此系统的学习了一下 一.openxml的格式 OPENXML( idoc int [ in] , XPathnvarchar [ in ] , [ flags ...
- 在SQL 语句批量替换数据库字符串的方法
update table[表名] set Fields[字段名]=replace(Fields[字段名],'被替换原内容','要替换成的内容')update ProgInfo set JoinTime ...
- 查看电脑已安装的Jdk的位数
查看自己电脑已安装的Jdk的位数的方法: public class ShowJdkBit { public static void main(String[] args) { String arch ...
- winform判断输入是否是数字
private bool IsNum(string str) { try { foreach (char c in str) { if (char.IsDigit(c)) return true; r ...
- C# 课堂总结4-类(常用的类)
一.string类 1. str.Length:字符串的长度 *****str[索引号] 2. str.Trim():去除左右两边的空格 *****str.TrimStart():去掉左边的空格str ...
- Jsp分页实例---真分页
网页的分页功能的实现比较简单,实现方法也多种多样. 今天总结一个简单的Jsp真分页实例. 首先,提到分页就要先明确一个概念,何为真分页何谓假分页. 假分页:一次性从数据库读出表的所有数据一次性的返回给 ...
- java--方法和成员的继承,访问
//在调用方法的时候,不是看句柄是哪一个类,而应该看对象是属于哪一个类的,属于哪一个类的,就调用哪一个类的成员和方法. //子类可以添加自己的新方法,但是子类对象的引用赋值给父类句柄之后,不能使用父类 ...
- Deamon Thread 讲解
The daemon thread's life cycle is same with the life cycle of the application which starts this daem ...
- STL 源代码剖析 算法 stl_algo.h -- equal_range
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie equal_range(应用于有序区间) ------------------------- ...