Uvalive 7269Snake Carpet (construction)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.