一道比较简单的题吧
可能读起来不太容易理解
就是给出n*m的矩阵,让你求出k条路径恰能把矩阵填满
要求是每条路径最短2格,路径上的格子要相邻
题意弄懂了就很好些了,贪心即可
前k-1次每次走2格,最后一次走完剩下的格子即可
代码如下:
#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 100010
#define ll long long
using namespace std;
int n, m, k, cnt, col, row;
int x[MAXN], y[MAXN];
int main(void) {
while(cin >> n >> m >> k) {
cnt = 1;
x[1] = 1; row = 1;
y[1] = 1; col = 1;
while(cnt <= n*m) {
cnt++;
if((col==m&&row%2) || (col==1&&row%2==0)) {
row++;
x[cnt] = row;
y[cnt] = col;
}
else {
if(row % 2) {
col++;
}
else {
col--;
}
x[cnt] = row;
y[cnt] = col;
}
}
/*
cout << cnt << endl;
for(int i=1; i<cnt; ++i) {
cout << x[i] << " " << y[i] << endl;
}
*/
int j = 1;
for(int i=1; i<k; ++i) {
cout << "2 " << x[j] << " " << y[j] << " ";
++j;
cout << x[j] << " " << y[j] << endl;
++j;
}
cout << cnt-j << " ";
for(int i=j; i<cnt-1; ++i) {
cout << x[i] << " " << y[i] << " ";
}
cout << x[cnt-1] << " " << y[cnt-1] << endl;
}
return 0;
}
现在再看真的感觉codeforces的第3题也没那么难么
以后要重新给自己定位了