• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

SGU 109 Magic of David Copperfield II

109. Magic of David Copperfield II

time limit per test: 0.5 sec. memory limit per test: 4096 KB

 

The well-known magician David Copperfield loves lo show the following trick: a square with N rows and N columns of different pictures appears on a TV screen, Let us number all the pictures in the following order:

1 2 ... N
... ... ... ...
N*(N-1)+1 N*(N-1)+2 ... N*N

Each member of the audience is asked to put a finger on the upper left picture (i.e., picture number one) and The Magic begins: the magician tells the audience to move the finger K1 times through the pictures (each move is a shift of the finger to the adjacent picture up, down, left or right provided that there is a picture to move to), then with a slight movement of his hand he removes some of the pictures with an exclamation "You are not there!", and ... it is true - your finger is not pointing to any of the pictures removed. Then again, he tells the audience to make K2 moves, and so on. At the end he removes all the pictures but one and smiling triumphantly declares, "I've caught you" (applause).
Just now, David is trying to repeat this trick. Unfortunately, he had-a hard day before, and you know how hard to conjure with a headache. You have to write a program that will help David to make his trick.

 

 

Input

The input file contains a single integer number N (1<N<101).

 

Output

Your program should write the following lines with numbers to the output file: K1 X1,1 X1,2 ... X1,m1 K2 X2,1 X2,2 ... X2,m2 ... Ke Xe,1 Xe,2 ... Xe,me where Ki is a number of moves the audience should make on the i-th turn (N<=Ki<300). All Ki, should be different (i.e. Ki<>Kj when i<>j). Xi,1 Xi,2 ... Xi,mi are the numbers of the pictures David should remove after the audience will make Ki moves (the number of the pictures removed is arbitrary, but each picture should be listed only once, and at least one picture should be removed on each turn). A description of the every next turn should begin with a new line. All numbers on each line should be separated by one or more spaces. After e iterations, all pictures except one should be removed.

 

Sample Input

 

3

 

 

 

Sample Output

 

3 1 3 7 9
5 2 4 6 8

 

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 5005
14 #define ll long long
15 #define INF 0x7fffffff
16 #define eps 1e-8
17 int n,m;
18 int main(){
19     while (~scanf("%d",&n)){
20         if (n == 2) { printf("3 4\n5 2 3\n"); continue; }
21         for (int k = 0; k < n+1; k++){
22             m = n;
23             if (k == 0)printf("%d", n);
24             else{
25                 if (n % 2 == 0)m--;
26                 printf("%d", m + 2 * k);
27             }
28             for (int i = 1; i <= n;i++)
29             for (int j = 1; j <= n;j++)
30             if (i + j == n+3-k||(k==0&&i+j>n+3-k))printf("% d", (i-1)*n + j);
31             puts("");
32         }
33     }
34     return 0;
35 }
View Code

 

posted @ 2013-11-01 16:10  HaibaraAi  阅读(102)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3