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\n",a[ii]);
    }
    return 0;
}

 

 
全部评论

相关推荐

03-02 16:31
已编辑
合肥工业大学 golang
程序员鼠鼠_春招版:学历可以,项目普通,评价多余,奖项没有,如果有面试都是因为学历给你的,我建议可以随便包几个奖项上去,像什么蓝桥杯天梯赛,虽然不一定有用,但是相比acm这种风险小多了,我几段实习下来,压根没查的,第二点是包一段小厂实习,大厂你不好拿捏,小厂打打杂也能让你在26里面出彩一点
点赞 评论 收藏
分享
昨天 11:19
已编辑
门头沟学院 Java
已经一年没发牛客了,为什么呢,因为没脸发...&nbsp;一年前的我自认为在25届中技术一流,八股无敌,项目出色,但是一年校招的蹉跎让我差点转行。24年春招收割了十几个实习&nbsp;offer&nbsp;之后我去了某家大厂实习到9月份转正失败,那时候的我还没有意识到噩梦将来,7月因为投秋招提前批没反馈,于是开始投了几个实习转正岗位练手又拿了3个中大厂&nbsp;offer,这时的我沉浸在我自以为是的骄傲里。9月秋招正式批开始后我几乎把我能找到的所有的岗位都投了一遍,只收获了大厂海笔,0面试。10月份第一家给我面试的公司是数字马力(蚂蚁的内包),诚恳的说,当时收到这家面试是嚣张的,觉得我拿这个&nbsp;offer&nbsp;如探囊取物,就当个保底吧。...
中街牛奶提子:是啊,不应该在秋招的时候继续投实习岗。也劝26届的,八月末后,实习岗就不应该投,给人错误的行情认知。佬是学院本,觉得约面难,双非何尝不是一样呢,秋招战场的激烈和实习完全不同。当时我秋招的时候也是边面实习,当时面实习面一个过一个觉得自己很优越,觉得能收获一堆实习offer那秋招肯定也行。为什么要在秋招拿一堆实习offer增强自己所谓的虚荣心,当时就是贱,为了所谓的攀比虚荣心
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务