Ultraviolet-769 magic of David Copperfield

Source: Internet
Author: User
The famous magician david copophil liked to perform the following magic: a matrix of N rows and n columns of different pictures appeared on the big screen. We named all the pictures as follows:

 

Each participating audience was asked to put their fingers on the picture on the top left (that is, the picture numbered 1). The magician started: the Magician told the audience to move K times on the image (move the finger to the top, bottom, left, and right adjacent pictures, if there is a picture there), and then he (the magician) and said, "You are not here." Then ...... It's true! Your finger did not point to any deleted image (pointing to the image) and then again. He told the audience to move the image for another 2 times ...... And so on. At the end, he deleted only the last image, and then successfully smiled and announced, "I have caught you !" (Applause ).

Now, David is going to perform this magic again. Unfortunately, he has a headache over the past few days. You know how hard it is to trick him into a headache! So you have to write a program to help the Group David make magic.

 
[Input] The input file contains an integer N (1 <n <101 ).
Output: Your program needs to output numbers as follows:
K1 X1, 1x1, 2... X1, M1
K2 X2, 1X2, 2... X2, m2
...
Ke XE, 1 XE, 2... XE, me
Ki is the number of steps for the audience to move (n <= Ki <= 300). All Ki must be complementary and different (that is, when I <> J, meet Ki <> kJ) XI, 1 Xi, 2... XI and MI are the images that David needs to delete after the audience perform the ki Movement (the order of the numbers is arbitrary, but each image can only be listed once, and at least one image is deleted each time ).
The description of each record must be in a new line. The numbers in each row must be separated by one or more spaces. After repeating e times, only one image is not deleted.

Idea: Construction, onion-style layer-by-layer Deletion

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int n;void cal() {int cnt = 2*n+1;int cur;for (int i = 1; i <= n; i++) {printf("%d", cnt);cnt += 2;cur = i;for (int j = 1; j <= i; j++) {printf(" %d", cur);cur += n-1;}printf("\n");}int d = n*(n-1)+1;for (int i = n-1; i > 1; i--) {printf("%d", cnt);cnt += 2;cur = d+(n-i);for (int j = 1; j <= i; j++) {printf(" %d", cur);cur -= n-1;}printf("\n");}}int main() {int t;scanf("%d", &t);while (t--) {scanf("%d", &n);cal();if (t)printf("\n");}return 0;}



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.