5 5 5 3 3 5 4 4 3 2 5 4 4 1 2 5 5 5 3 3 6 6 5 4 4 3 2 6 6 5 4 4 1 2 6 6 5 5 5 3 3 6 6 5 4 4 3 2 6 6 5 4 4 1 2 7 6 7 7 7 7 7 7 6 剩下自己领悟规律#include <bits/stdc++.h> using namespace std; const int N = 520; int a[N][N]; int row, col; void get(int m){ if(m == 1){ puts("1 1"); puts("1 1"); } else if(m == 2) { puts("1 3"); puts("1 1\n1 2 1 3"); } else if(m == 3){ puts("2 3"); puts("1 2"); puts("1 3 2 3"); puts("1 1 2 1 2 2"); }else if(m == 4){ puts("2 5\n1 4\n1 5 2 5\n1 1 2 1 2 2\n1 2 1 3 2 3 2 4") ; }else if(m == 5){ puts("3 5\n3 4\n1 4 1 5\n2 4 2 5 3 5\n2 2 2 3 3 3 3 2\n3 1 2 1 1 1 1 2 1 3"); } } bool cmp1(pair<int, int> a, pair<int, int> b) { if(a.second != b.second) return a.second < b.second; if(a.second % 2 == 0){ return a.first > b.first; }else{ return a.first < b.first; } } bool cmp2(pair<int, int> a, pair<int, int> b) { if(a.first != b.first) return a.first > b.first; return a.second < b.second; } int main(){ int n; a[1][1] = 3; a[2][1] = 3; a[1][2] = 3; a[3][1] = 1; a[2][2] = a[3][2] = 2; a[1][3] = a[1][4] = a[2][3] = a[2][4] = 4; a[3][3] = a[3][4] = a[3][5] = a[2][5] = a[1][5] = 5; while(cin >> n){ a[1][1] = 3; a[2][1] = 3; a[1][2] = 3; a[3][1] = 1; a[2][2] = a[3][2] = 2; a[1][3] = a[1][4] = a[2][3] = a[2][4] = 4; a[3][3] = a[3][4] = a[3][5] = a[2][5] = a[1][5] = 5; if(n < 6) get(n); else { row = 3, col = 5; for(int i = 6; i <= n; i++){ if(i %2 == 0){ for(int j = 1; j <= row; j++){ a[j][col+1] = a[j][col+2] = i; } col += 2; } else{ for(int j = 1; j <= col; j++) a[row+1][j] = i; row++; swap(a[row-1][col-1], a[row][col]); } } vector<pair<int, int> > ans[550]; for(int i = 1; i <= row; i++){ for(int j = 1; j <= col; j++) { ans[a[i][j]].push_back(make_pair(i, j)); } } printf("%d %d\n", row, col); puts("3 4\n1 4 1 5\n2 4 2 5 3 5\n2 2 2 3 3 3 3 2\n3 1 2 1 1 1 1 2 1 3"); for(int i = 6; i <= n; i++) { if(i%2 == 0){ sort(ans[i].begin(), ans[i].end(), cmp1); }else{ sort(ans[i].begin(), ans[i].end(), cmp2); } } for(int i = 6; i <= n; i++) { for(int j = 0; j < ans[i].size(); j++) { printf("%d %d ", ans[i][j].first, ans[i][j].second); } puts(""); } } } return 0; }
UVALive 7269 Snake Carpet
最新推荐文章于 2018-10-09 23:12:48 发布