zoukankan      html  css  js  c++  java
  • A.Snake Filled

    “What a boring world!”
    Julyed felt so bored that she began to write numbers on the coordinate paper. She wrote a “0” on the center, then wrote the follow numbers clockwise, which looked like a snake as below.
     
    “Damn! I have fulfilled the paper!”
    Julyed was looking at paper. Suddenly, she began to feel curious.
    “What is the nth number on the positive axis of Y axis?”
    She asked tomriddly for the question. But tomriddly was so busy that he ignored Julyed. So now you have to solve this problem.

    输入

    Multiple test cases.
    The first line contains an integer T (T <= 50), indicating the number of test cases.
    Then T lines follows, one line per case. Each line contains a positive integer n (n <= 3000).

    输出

    One line per case. An integer indicates the nth number on the positive axis of Y axis.

    样例输入

    3
    1
    2
    18
    

    样例输出

    5
    18
    1314
    

    CODE:

    #include <stdio.h>

    int xun(int n)

    {

          int i;

          if(n==0)

               i=0;

          else i=xun(n-1)+5+8*(n-1);

          return i;

    }

    int main()

    {

          int n,i,T,num;

          while(scanf("%d",&T)!=EOF)

          {

               for(i=0;i<T;i++)

               {

                     scanf("%d",&n);

                     num=xun(n);

                     printf("%d ",num);

               }

          }

          return 0;

    }
     
  • 相关阅读:
    ruby
    Ajax的基本请求/响应模型
    面向GC的Java编程(转)
    linux中fork()函数详解(转)
    详细解析Java中抽象类和接口的区别(转)
    MQ队列堆积太长,消费不过来怎么办(转)
    消息队列软件产品大比拼(转)
    mac地址和ip地址要同时存在么?
    DP刷题记录(持续更新)
    ZR979B. 【十联测 Day 9】唯一睿酱
  • 原文地址:https://www.cnblogs.com/shu233/p/5575560.html
Copyright © 2011-2022 走看看