Title: Portal.
Test instructions: Constructs a matrix that allows the matrix to contain n snakes, each with a length of 1 to N, and an odd-length snake with odd turns, even lengths
Snake has an even number of turning.
Odd and even numbers are constructed separately, and odd numbers can be:
1357
3357
5557
7777
This is always constructed so that even numbers can:
2266
4466
4466
8888
8888
Keep the right side and put the face down.
Then preprocess each of the snake's coordinates, and then consider whether the even number is placed on the right or bottom of the odd part.
#include <bits/stdc++.h>using namespacestd;#defineMAXN 1111structPoint {intx, y;}; Vector<point>P[MAXN];intN;voidinit () { for(inti =1; I <= +; i++) {p[i].clear (); } for(inti =1; I <= +; i++) { if(i&1) { intx = (i+1)/2; inty =x; for(intj =1; J <= X; J + +) {P[i].push_back (point) {x, J}); } for(intj = X1; J >=1; j--{P[i].push_back (point) {j, y}); } } Else { if(i = =2) {p[2].push_back (point) {1,1}); p[2].push_back (point) {1,2}); } Else if((i>>1) &1) { inty = i>>1; for(intj =1; J <= y; J + +{P[i].push_back (point) {j, y}); } for(intj = y; J >=1; j--) {P[i].push_back (point) {j, Y+1}); } } Else { intx = i>>1; for(intj =1; J <= X; J + +) {P[i].push_back (point) {x, J}); } for(intj = x; J >=1; j--) {P[i].push_back (point) {x+1, J}); } } } }}intMain () {init (); while(SCANF ("%d", &n) = =1) { if(((n+1)/2) &1) {//even on the right .printf ("%d%d\n", (n+1) >>1, (n/2) + (n/2)+1); for(inti =1; I <= N; i++) { for(intj =0; J < P[i].size (); J + +) { if(i&1) {printf ("%d%d%c", p[i][j].x, p[i][j].y, j = = P[i].size ()-1?'\ n':' '); } Else{printf ("%d%d%c", p[i][j].x, p[i][j].y+ (n+1) >>1), J = = P[i].size ()-1?'\ n':' '); } } } } Else{//The even number is placed belowprintf ("%d%d\n", (n/2) + (n/2)+1, (n+1) >>1); for(inti =1; I <= N; i++) { for(intj =0; J < P[i].size (); J + +) { if(i&1) {printf ("%d%d%c", p[i][j].x, p[i][j].y, j = = P[i].size ()-1?'\ n':' '); } Else{printf ("%d%d%c", P[i][j].x+ ((n+1) >>1), p[i][j].y, J = = P[i].size ()-1?'\ n':' '); } } } } } return 0;}
Uvalive 7269Snake Carpet (construction)