-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path252C.cpp
183 lines (136 loc) · 2.59 KB
/
252C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*--------------------- Author - Akshit ----------------------*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<list>
#include<queue>
#include<cstdlib>
#include<numeric>
#include<set>
#include<map>
#include<deque>
#include<climits>
#include<cassert>
#include<cctype>
#include<ctime>
#include<iterator>
#include<iomanip>
#include<functional>
#include<fstream>
#include<ostream>
#include<istream>
#include<sstream>
using namespace std;
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d",n)
#define pfln(n) printf("%d\n",n)
#define vi vector <int >
#define pb push_back()
#define debug(n) printf("n = %d\n",n)
#define PI 3.14159265358979
#define LL 1000000007
int main()
{
std::ios_base::sync_with_stdio(false);
int n,m,k,row,col;
int cnt = 0;int nut = 0;int flag = 0;
cin>>n>>m>>k;
for(int i = 1 ; i <=n ; i++){
if(k == 1){col = 1;row = 1;break;}
if(i%2 == 1){
for(int j = 1 ; j<=m ; j++){
if(nut == k-1){
flag = 1;
col = j;
row = i;
cout<<"\n";
break;
}
if(cnt == 0)
cout<<"2 ";
cout<<i<<" "<<j<<" ";
cnt++;
if(cnt % 2 == 0 && cnt !=0){
nut++;
if(nut!=k-1){
cout<<"\n";
cout<<"2 ";}
if(nut == k-1){
flag = 1;
col = j;row = i;cout<<"\n";
break;
}
}
}
}
if(flag == 1)break;
if(i%2 == 0){
for(int j = m ; j>=1 ; j--){
if(nut == k-1 ){
flag = 1;
row = i;
col = j;
cout<<"\n";
break;}
cout<<i<<" "<<j<<" ";
cnt++;
if(cnt % 2 == 0 && cnt != 0){
nut++;
if(nut == k-1){
flag = 1;
row = i;
col = j;
cout<<"\n";
break;
}
cout<<"\n";
cout<<"2 ";
}
}
}
if(flag == 1)break;
}
//cout<<"out\n";
int rem = n*m-(2*(k-1));
cout<<rem<<" ";
//cout<<"row = "<<row <<" col = "<<col<<endl;
if (row%2 == 1){
if(k!=1)
for(int j = col+1 ; j<=m ; j++){
cout<<row<<" "<<j<<" ";
}
if(k == 1)
for(int j = col ; j<=m ; j++){
cout<<row<<" "<<j<<" ";
}
}
if(row%2 == 0){
if(k!=1)
for(int j = col-1 ; j>=1 ; j--){
cout<<row<<" "<<j<<" ";
}
if(k==1)
for(int j = col ; j>=1 ; j--){
cout<<row<<" "<<j<<" ";
}
}
row = row+1;
for(int i = row ; i <=n ; i++){
if(i%2 == 1){
for(int j = 1 ; j<=m ; j++){
cout<<i<<" "<<j<<" ";
}
}
if(i%2 == 0){
for(int j = m ; j>=1; j--){
cout<<i<<" "<<j<<" ";
}
}
}
return 0;
}