首页 > ACM题库 > HDU-杭电 > hdu 2153 仙人球的残影-动态规划-[解题报告]C++
2013
12-30

hdu 2153 仙人球的残影-动态规划-[解题报告]C++

仙人球的残影

问题描述 :

在美丽的HDU,有一名大三的同学,他的速度是众所周知的,跑100米仅仅用了2秒47,在他跑步过程中会留下残影的哎,大家很想知道他是谁了吧,他叫仙人球,既然名字这样了,于是他的思想是单一的,他总是喜欢从一点出发,经过3次转折(每次向右转90°),回到出发点,而且呢,他每次转折前总是跑相同长度的路程,所以很多人都想知道如果用‘1’算他跑步出发的第一个残影的话,那么回到起点的时候,他的残影是怎么样的呢?

输入:

测试数据有多行,每一行为一个数N(1<=N<=10)(以0结尾,0不做处理),即仙人球在没有回到起点的时候,跑过留下N个残影后突然90°右转。

输出:

测试数据有多行,每一行为一个数N(1<=N<=10)(以0结尾,0不做处理),即仙人球在没有回到起点的时候,跑过留下N个残影后突然90°右转。

样例输入:

4

样例输出:

  1  2  3  4
 12        5
 11        6
 10  9  8  7

2011-12-16 12:50:14

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2153

题意:中文,模拟。。。

代码:

# include <stdio.h>
# include <String.h>


int dp[15][15] ;


void gao(int n)
{
    int i, tab[4][2] = {0, 1, 1, 0, 0 , -1, -1, 0} ;
    int d = 0, x, y ;
    memset (dp, 0, sizeof(dp)) ;
    dp[1][1] = 1 ;
    x = 1, y = 2 ;
    for (i = 2 ; i <= (n-1)*4 ; i++)
    {
        dp[x][y] = i ;
        if ((i-1)%(n-1)==0) d++ ;
        x += tab[d][0] ;
        y += tab[d][1] ;
    }
}


void output(int n)
{
    int i, j ;
    for (i = 1 ; i <= n ; i++)
    {
        for (j = 1 ; j<= n ; j++)
        {
            if (dp[i][j] == 0) printf ("") ;
            else printf ("%3d", dp[i][j]) ;
        }
        printf ("\n") ;
    }
}



int main ()
{
    int n ;
    while (~scanf ("%d", &n))
    {
        gao(n) ;
        output(n) ;
    }
    return 0 ;
}

解题转自:http://www.cnblogs.com/lzsz1212/archive/2012/01/06/2315013.html


  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.