CodeForces 441C Valera and Tubes
来源:互联网 发布:7.0采集助手数据库 编辑:程序博客网 时间:2024/05/16 12:50
链接:http://codeforces.com/problemset/problem/441/C
Valera and Tubes
Valera has got a rectangle table consisting of n rows andm 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 rowx 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 integerri (the number of tube cells), then print2ri 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)
3 3 3
3 1 1 1 2 1 33 2 1 2 2 2 33 3 1 3 2 3 3
2 3 1
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
Picture for the second sample:
思路:因为只要填满格子,并且要求每个管子最少占据两个格子。那么只要k-1个管子每个管子占据两个格子,剩下的一个管子占据剩下的所有格子。这样得到的一定是正解当中的一个解。
附上AC代码:
#include <iostream>#include <cstdio>#include <string>#include <cmath>#include <iomanip>#include <ctime>#include <climits>#include <cstdlib>#include <cstring>#include <cctype>#include <algorithm>#include <queue>#include <vector>#include <set>#include <map>#include <stack>#include <deque>//#pragma comment(linker, "/STACK:102400000, 102400000")using namespace std;typedef long long ll;const double pi = acos(-1.0);const double e = exp(1.0);const double eps = 1e-8;int n, m, k;int main(){ios::sync_with_stdio(false);while (~scanf("%d%d%d", &n, &m, &k)){int x=1, y=1;bool flag = false;for (int i=1; i<k; i++){printf("2");for (int j=0; j<2; j++){printf(" %d %d", x, y);if (!flag) y++;else y--;if (y > m){flag = !flag;x++; y=m;}if (y < 1){flag = !flag;x++; y=1;}}printf("\n");}printf("%d", n*m-2*k+2);while (x <= n){printf(" %d %d", x, y);if (!flag) y++;else y--;if (y > m){flag = !flag;x++; y=m;}if (y < 1){flag = !flag;x++; y=1;}}printf("\n");}return 0;}
- Codeforces 441C Valera and Tubes
- CodeForces 441C Valera and Tubes
- Codeforces - 441C-Valera and Tubes
- Codeforces Round #252 (Div. 2) 441C. Valera and Tubes
- Codeforces #252 (Div. 2) C. Valera and Tubes
- Codeforces Round #252 (Div. 2) C. Valera and Tubes
- Codeforces Round #252(Div. 2) 441C. Valera and Tubes 构造
- Valera and Tubes
- CodeForces 369C. Valera and Elections
- codeforces 369C Valera and Elections DFS
- codeforces 216 DIV C. Valera and Elections
- codeforces 369C Valera and Elections
- CodeForces 441 A. Valera and Antique Items
- Codeforces 441 B. Valera and Fruits
- Codeforces 441 E. Valera and Number
- CodeForces 441A Valera and Antique Items
- CodeForces 441B Valera and Fruits
- codeforces-441B-Valera and Fruits【暴力】
- 软考路之线性表
- linux 编写自己的shell
- POJ 3905 Perfect Election(2-SAT)
- 海量数据挖掘MMDS week2: Nearest-Neighbor Learning最近邻学习
- Asphalting Roads
- CodeForces 441C Valera and Tubes
- OpenCV 学习(像素操作 Manipuating the Pixels)
- UIApplication和delegate以及程序启动过程
- 海量数据挖掘MMDS week2: Association Rules关联规则与频繁项集挖掘
- 证券基础--发行体制
- html小需求——科技文章展示
- Cocos2D绘制纹理的一般方法
- [283]Move Zeroes
- Struts2的package的的命名空间(默认命名空间与根命名空间)