LA 7269 Snake Carpet (law, simulation)

Source: Internet
Author: User

Test instructions: Given a number n, indicating that there are n snakes, and then the length of the snake is I, if I is odd, then it can only turn odd number of bends, if the even number can only turn even several, 1, 2 except, and then put the N snake,

Put it in a w*h matrix, ask for exactly full, let you output a solution, if not, output 0 0.

Analysis: This topic is to find the law, first draw the first few, draw to 7th, should be able to find the law, assuming now is the 6th, and is the last one, then we can on the 5th basis, in the matrix of the

Put two columns on the right, just 6, and the turn is even, if it is to put to 7, then you can put, the 7th, put to the 4th row to sixth column again to the previous, just 7, on the right two rows,

Just 6, put on 6. Everything else can be pushed in turn.

Note that the order of the output is to be output in the order of the snakes, and the body cannot be disconnected.

The code is as follows:

#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype>using namespace STD; typedef long Long Ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3  F3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = 1e6 + 5;const int mod = 1e9 + 7;const int dr[]  = {0, 0,-1, 1};const int dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 && R < n && C >= 0 && C < m;}    void Solve () {if (n & 1) printf ("%d%d\n", n/2+1, N);    else printf ("%d%d\n", N/2, n+1);  Puts ("3 4");  Puts ("1 4 1 5");  Puts ("2 4 2 5 3 5");  Puts ("2 2 2 3 3 3 3 2");    Puts ("3 1 2 1 1 1 1 2 1 3");    if (n & 1) m = n; else m = n-1;        for (int i = 6; I <= m; ++i) {int x = (i+1)/2;            if (I & 1) {for (int j = 1; j < i; ++j) printf ("%d%d", X, J);        printf ("%d%d\n", x-1, i-1);            } else{int yy = i/2-1;            for (int j = yy; j > 0;--j) printf ("%d%d", j, I);            for (int j = 1; j <= x; ++j) printf ("%d%d", J, I+1);        printf ("%d%d\n", x+1, i+1);    }} if (n & 1) return;    for (int i = N/2; i > 0; i) printf ("%d%d", I, N);    for (int i = 1; i < N/2; ++i) printf ("%d%d", I, n+1); printf ("%d%d\n", N/2, n+1);}        int main () {while (scanf ("%d", &n) = = 1) {if (1 = = N) printf ("1 1\n1 1\n");  else if (2 = = N) {printf ("1 3\n");  printf ("1 1\n");        printf ("1 2 1 3\n");  } else if (3 = = N) {puts ("2 3");  Puts ("1 2");  Puts ("1 3 2 3");        Puts ("1 1 2 1 2 2");         } else if (4 = = N) {   Puts ("2 5");  Puts ("1 4");  Puts ("1 5 2 5");  Puts ("1 1 2 1 2 2");        Puts ("1 2 1 3 2 3 2 4");  } else if (5 = = N) {puts ("3 5");  Puts ("3 4");  Puts ("1 4 1 5");  Puts ("2 4 2 5 3 5");  Puts ("2 2 2 3 3 3 3 2");        Puts ("3 1 2 1 1 1 1 2 1 3");    } else solve (); } return 0;}

LA 7269 Snake Carpet (law, simulation)

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.