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 ...
 
随机推荐
- QML基础(六篇文章)
			
http://www.cnblogs.com/hicjiajia/category/350988.html
 - jsp字段判空
			
是对象吧String jsp的写法 <% if(str == null) { %> str is null <% } else { %> str not null <% ...
 - CMake初步(1)
			
转自:<你所不知的OSG>第一章:CMake初步(1)http://bbs.osgchina.org/forum.php?mod=viewthread&tid=1189&f ...
 - 北京创客空间 BEIJING MAXPACE的小站
			
北京创客空间 BEIJING MAXPACE的小站 北京市海淀区海淀大街1号中关村梦想实验室(原中关村国际数字设计中心)4层
 - android大牛高焕堂最新力作-android架构师之路
			
android大牛高焕堂 个人介绍: Android专家顾问,台湾Android论坛主席,现任亚太地区Android技术大会主席,台湾Android领域框架开发联盟总架构师.发表100多篇Androi ...
 - 【C语言】数字在排序数组中出现的次数(改动)
			
//数字在排序数组中出现的次数(改动) //统计一个数字在排序数组中出现的次数.比如:排序数组{1,2,3,3,3.3,4,5}和数字3,因为3出现了4次,因此输出4. #include <st ...
 - QSerialPort
			
(草稿) qt5提供QSerialPort类,封装了串口的api, 可以用这个类写串口通信程序.
 - NGINX服务器打开目录浏览功能
			
我们做文件服务器的时候,希望打开目录浏览的功能.但是Nginx默认是不允许列出目录功能的.若需要此功能,需要在配置文件中手动开启. 首先需要打开开关.autoindex on;autoindex_ex ...
 - 演练2-1:创建MVC默认项目
			
在VS2012中点击“文件 | 新项目”,在弹出对话框中选择“Visual C# | Web | ASP.NET MVC 4 Web应用程序”. 在弹出的模板对话框中选择“Internet应用程序”和 ...
 - Qt 智能指针学习(7种QT智能指针和4种std智能指针)
			
从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...