C. Valera and Tubestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Valera has got a rectangle table consistingNRows andMColumns. 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 rowXAnd columnYBy a pair of integers (X, Bytes,Y).
Valera wants to place exactlyKTubes on his rectangle table. A tube is such sequence of table cells (X1, bytes,Y1 ),(X2, bytes,Y2 ),...,(XR, Bytes,YR), That:
- RLimit ≥ limit 2;
- For any integerI(1 digit ≤ DigitILimit ≤ limitREncryption-interval 1) the following equation |XIAccept-Encoding-XILatency + latency 1 | latency + latency |YIAccept-Encoding-YICalifornia + California 1 | California = California 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 arrangeKTubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integersN, Bytes,M, Bytes,K(2 cores ≤ CoresN, Bytes,MLimit ≤ limit 300; 2 limit ≤ limit 2KLimit ≤ limitN·M)-The number of rows, the number of columns and the number of tubes, correspondingly.
Output
PrintKLines. InI-Th line print the description ofI-Th tube: first print integerRI(The number of tube cells), then print 2RIIntegersXI1, bytes,YI1, bytes,XI2, bytes,YI2, middle..., middle ,...,XIrI, Bytes,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 33 2 1 2 2 2 33 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 longusing 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;}
In addition, there is a strange phenomenon, if you put cnt ++ in printf, the test is as follows:
<pre name="code" class="cpp">#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 100000#define ll long longusing 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;}
This makes it easy to understand. Because printf is compiled from the right to the left, cnt ++ achieves auto-increment.