ACM/ICPC Beijing Live Race I question
Structure
Notice a small pit where the output of each snake is to be output from beginning to end.
Also note that you cannot open the array to simulate the construction process, and then output, that will be tle.
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;Const intmaxn= -+Ten; Vector<int>G[MAXN];intfind[maxn][3];intN;intr1,c1,r2,c2;inttot;intANS[MAXN][MAXN];voidf () {find[2][1]=1; find[2][2]=2; find[4][2]=2; for(intI=4; i<= -; i=i+2) { if(i%4==0) find[i][1]=find[i-2][1]+2; Elsefind[i][1]=find[i-2][1]; } for(intI=4; i<= -; i=i+2) { if(i%4==2) find[i][2]=find[i-2][2]+2; Elsefind[i][2]=find[i-2][2]; }}voidinit () {//Clear for(intI=0; i<=n;i++) g[i].clear (); Tot=0; //determine the size of the left graphR1=c1= (n+1)/2; //determine the size of the right image if(n%2==1) {R2=find[n-1][1]; C2=find[n-1][2]; } Else{R2=find[n][1]; C2=find[n][2]; }}voidOdd () { for(intI=1; i<=n;i=i+2) {tot++; for(intj=1; j<=tot;j++) {g[i].push_back (tot); G[i].push_back (j); ANS[TOT][J]=i; } for(intj=tot-1; j>=1; j--) {g[i].push_back (j); G[i].push_back (TOT); Ans[j][tot]=i; } }}voideven () {if(r1==S2) { intNowr=1; intNowc=0; for(intI=2; i<=n;i=i+2) { //horizontal painting. if(i%4==0) { for(intj=1; j<=i/2; j + +) {g[i].push_back (Nowr+1); G[i].push_back (J+C1); ANS[NOWR+1][j+c1]=i; } for(intj=i/2; j>=1; j--) {g[i].push_back (Nowr+2); G[i].push_back (J+C1); ANS[NOWR+2][j+c1]=i; } NOWR=nowr+2; } //vertical painting. Else { for(intj=1; j<=i/2; j + +) {g[i].push_back (j); G[i].push_back (NOWC+1+C1); ANS[J][NOWC+1+c1]=i; } for(intj=i/2; j>=1; j--) {g[i].push_back (j); G[i].push_back (NOWC+2+B1); ANS[J][NOWC+2+c1]=i; } NOWC=nowc+2; } } } Else if(r1==C2) {swap (R2,C2); intnowr=r2+1; intNowc=1; for(intI=2; i<=n;i=i+2) { //vertical painting. if(i%4==0) { for(intj=r2;j>=r2-i/2+1; j--) {g[i].push_back (j); G[i].push_back (NOWC+1+C1); ANS[J][NOWC+1+c1]=i; } for(intj=r2-i/2+1; j<=r2;j++) {g[i].push_back (j); G[i].push_back (NOWC+2+C1); ANS[J][NOWC+2+c1]=i; } NOWC=nowc+2; } //horizontal painting. Else { for(intj=1; j<=i/2; j + +) {g[i].push_back (Nowr-1); G[i].push_back (J+C1); ANS[NOWR-1][j+c1]=i; } for(intj=i/2; j>=1; j--) {g[i].push_back (Nowr-2); G[i].push_back (J+C1); ANS[NOWR-2][j+c1]=i; } NOWR=nowr-2; } } }}voidprint () { for(intI=1; i<=n;i++) { for(intj=0; J<g[i].size (); j + +) {printf ("%d", G[i][j]); if(J<g[i].size ()-1) printf (" "); Elseprintf"\ n"); } }}intMain () {f (); while(~SCANF ("%d",&N)) {init ();//InitializeOdd ();//left ImageEven ();//Right Image /*for (int i=1;i<=r1;i++) {for (int j=1;j<=c1+c2;j++) {printf ( "%5d", Ans[i][j]); } printf ("\ n"); } */printf ("%d%d\n", r1,c1+C2); Print ();//Output } return 0;}
Hihocoder 1257 Snake Carpet (very simple construction method)