标签:c style class blog code java
贪心算法,每条路径最短2格,故前k-1步每次走2格,最后一步全走完
由于数据比较小,可以先打表
#include <iostream> #include <vector> #include <algorithm> #include <utility> using namespace std; typedef pair<int,int> Point; int main(){ int n, m, k, flag = -1; cin >> n >> m >>k; vector<Point> table; for(int i = 0 ; i < n ; ++i){ flag*=-1; for(int j = 0; j < m; ++ j){ table.push_back(Point(i,flag>0 ? j : (m-1-j))); } } for(int i = 0 ; i <2*(k -1); i+=2){ cout<<2<<" "<<table[i].first+1<<" "<<table[i].second+1<<" "<<table[i+1].first+1<<" "<<table[i+1].second+1<<endl; } cout<<m*n-2*(k-1); for(int i = 2*(k-1); i < m*n; ++ i ){ cout<<" "<<table[i].first+1<<" "<<table[i].second+1; } cout<<endl; }
关于额外的信息, |xi?-?xi?+?1|?+?|yi?-?yi?+?1|?=?1,其实就是一个点的四连通区域,即上下左右4个点
codeforces Round #252 (Div. 2) C - Valera and Tubes,布布扣,bubuko.com
codeforces Round #252 (Div. 2) C - Valera and Tubes
标签:c style class blog code java
原文地址:http://www.cnblogs.com/xiongqiangcs/p/3778676.html