一道比較簡單的題吧
可能讀起來不太容易理解
就是給出n*m的矩陣,讓你求出k條路徑恰能把矩陣填滿
要求是每條路徑最短2格,路徑上的格子要相鄰
題意弄懂了就很好些了,貪心即可
前k-1步每次走2格,最後一次走完剩下的格子即可
代碼如下:
#include <cstdio>#include <iostream>#include <algorithm>#define MAXN 100010#define ll long longusing 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題也沒那麼難麼
以後要重新給自己定位了