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 ...
随机推荐
- Webgrid参数格式
显示图片 grid.Column(null,"图片",format:p=>Html.Raw(string.Format("<img src='{0}'/> ...
- linux c 得到时间
ctime: 将时间和日期以字符串格式表示头文件: time.h函数定义: char *ctime(const time_t *timep); 应用举例:#include <stdio.h> ...
- 各国iPhone5系列最新裸机价格
美国/加拿大/中国香港/中国大陆iPhone5系列最新裸机价格
- Linux下动态库使用
1. 静态库和动态库的基本概念 静态库,是在可执行程序连接时就已经加入到执行码中,在物理上成为执行程序的一部分:使用静态库编译的程序运行时无需该库文件支持,哪里都可以用, 但是生成的可执行文件较大.动 ...
- Mac OSX的开机启动配置
Login Items Mac OSX的当前用户成功登录后启动的程序,该类别的启动项配置文件存放在~/Library/Preferences/com.apple.loginitems.plist,所以 ...
- PHP - 验证用户名
/** * * 函数名:_check_username($user_str,$min_num,$max_num); * 作用:检测用户名是否符合格式 * 参数: * 1:用户名 * 2:不得小于多少位 ...
- 使Web Api 支持跨域资源共享(CORS)
Reference:http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api Imp ...
- 配置nexus仓库
Nexus有许多默认仓库:Central,Releases,Snapshots,和3rd Party 1.配置central仓库 Nexus内置了Maven中央代理仓库Central.选择仓库列表中的 ...
- 云计算被视为继大型计算机、个人计算机、互联网之后的第4次IT产业革命,顺应了当前各行业整合计算资源和服务能力的要求(转)
云计算被视为继大型计算机.个人计算机.互联网之后的第4次IT产业革命,顺应了当前各行业整合计算资源和服务能力的要求,成为引领当今世界信息技术变革的主力军.越来越多的金融企业认识到只有与云计算结合,才能 ...
- static在C和C++中的用法和区别
static主要有三个作用: (1)局部静态变量 (2)外部静态变量/函数 (3)静态数据成员/成员函数 前两种C和C++都有,第三种仅在C++中有,下面分别作以下介绍: 一.局部静态变量 在C/C+ ...