zoukankan      html  css  js  c++  java
  • 2101 Problem 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

    解题心得:
      输入0,1,2...,然后对应输出黄色标记的数字。此题纯靠找规律即可解答。
      我找到的规律是这样的:0,5,18,39 ,每次增加的数add[1]=4,add[2]=13,add[3]=21,然后发现每个add之间都是增加8;
      下面是代码。

    代码:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    int main()
    {
        int n;
        int add=5;
        int a[3005];
        int z=8;
        int s=0;
        int ii;
        memset(a,0,3005*sizeof(int));
        cin>>n;
        for(int i=0;i<n;i++){
            for(int j=1;j<=3000;j++){
                s+=add;
                a[j]=s;
                add+=z;
            }
            s=0;
            add=5;
            scanf("%d",&ii);
            printf("%d
    ",a[ii]);
        }
        return 0;
    }
     
  • 相关阅读:
    mapxtreme2005 改变选中的图元样式
    hdu 3044 Dog and dog
    jdoj 1008 最短路径问题 代码及分析
    jdoj 1402 特殊的数 代码及分析
    poj 1125 Stockbroker Grapevine 代码及分析
    hdu 1063 Exponentiation代码及分析
    堆和栈的区别 (转贴)
    文本长度控制
    一点设计上的创意,有机会就去实现
    IECookiesView (Cookies查看工具)绿色汉化版 V1.74
  • 原文地址:https://www.cnblogs.com/TWS-YIFEI/p/5574530.html
Copyright © 2011-2022 走看看