题目描述

“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.

样例输入

  1. 3
  2. 1
  3. 2
  4. 18

样例输出

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

  6. 代码:
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n;
  10. int add=;
  11. int a[];
  12. int z=;
  13. int s=;
  14. int ii;
  15. memset(a,,*sizeof(int));
  16. cin>>n;
  17. for(int i=;i<n;i++){
  18. for(int j=;j<=;j++){
  19. s+=add;
  20. a[j]=s;
  21. add+=z;
  22. }
  23. s=;
  24. add=;
  25. scanf("%d",&ii);
  26. printf("%d\n",a[ii]);
  27. }
  28. return ;
  29. }
  1.  

2101 Problem A Snake Filled的更多相关文章

  1. codeforce gym/100495/problem/F Snake++——DFS应用

    emmmm.... 在被新生暴打后,我花了很久才补出这道DFS.由于WA1检查了半天,最后竟然是输出少了一个:   ,心态小崩. 这里普通的dfs算出的连通区域并不能直接当做最后的答案.所以需要类似模 ...

  2. 2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest)

    2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest) Problem A. M ...

  3. OpenFOAM Tutorial Standard Solvers【转载】

    转载自:http://www.cnblogs.com/fortran/articles/1996927.html boundaryFoam Steady-state solver for 1D tur ...

  4. TJU Problem 2101 Bullseye

    注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<& ...

  5. HDU 2101 A + B Problem Too 分类: ACM 2015-06-16 23:57 18人阅读 评论(0) 收藏

    A + B Problem Too Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  7. Codeforces 510 A.Fox and Snake

    题目链接:http://codeforces.com/contest/510/problem/A A. Fox And Snake time limit per test2 seconds memor ...

  8. A - Fox And Snake

    Problem description Fox Ciel starts to learn programming. The first task is drawing a fox! However, ...

  9. [LeetCode] Design Snake Game 设计贪吃蛇游戏

    Design a Snake game that is played on a device with screen size = width x height. Play the game onli ...

随机推荐

  1. codeforces CF475 ABC 题解

    Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...

  2. standford工具-parser

    stanford自然语言处理开源了很多工具,很实用也很方便,记录下来,以备后用. 第一篇就从句法分析开始吧(所用的平台都是java+eclipse). <一>操作 1.http://www ...

  3. JQ分页功能

    HTML <div id='page'></div> <div id='con'></div> CSS span{width: 60px;height: ...

  4. UGUI事件解析

    http://www.tuicool.com/articles/7fYjMr http://www.xuanyusong.com/archives/3325

  5. [译] ASP.NET MVC 6 attribute routing – the [controller] and [action] tokens

    原文:http://www.strathweb.com/2015/01/asp-net-mvc-6-attribute-routing-controller-action-tokens/ 当在Web ...

  6. 安装cocopods

    http://www.tuicool.com/articles/7VvuAr3 OS 最新版 CocoaPods 的安装流程 1.移除现有Ruby默认源 $gem sources --remove h ...

  7. HDOJ 4336 Card Collector

    容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. Linux下运行C语言程序

    一.编写C语言的源代码 二.用gcc -c C文件名生成.o文件 三.用gcc -o 可执行文件名 .o文件名 生成可执行文件 四.输入可执行文件名前加./执行可执行文件

  9. 【C语言入门教程】5.3 函数的调用 与 参数

    函数通过调用获得程序的控制权,函数的参数是调用者与函数的数据接口.函数可以定义一个或多个参数,也可以省略参数,调用时将与参数的数据类型相匹配的数据置于参数列表中,即可在函数体内使用.参数的调用有多种形 ...

  10. LoadRunner脚本编写(转)

    性能测试工程师要懂代码么?答案是必须的.好多测试员认为在loadrunner中编写脚本很难很牛X ,主要是大多测试人员并未做过开发工作,大学的那点程序基础也忘记的差不多了.还有非计算机专业出身的测试员 ...