题目描述

“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=;
int a[];
int z=;
int s=;
int ii;
memset(a,,*sizeof(int));
cin>>n;
for(int i=;i<n;i++){
for(int j=;j<=;j++){
s+=add;
a[j]=s;
add+=z;
}
s=;
add=;
scanf("%d",&ii);
printf("%d\n",a[ii]);
}
return ;
}
 

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. H5移动端知识点总结

    H5移动端知识点总结 阅读目录 移动开发基本知识点 calc基本用法 box-sizing的理解及使用 理解display:box的布局 理解flex布局 Flex布局兼容知识点总结 回到顶部 移动开 ...

  2. Linq→join中指定多个条件

    还是习惯先撸一段SQL * FROM User_Pic P AND P.Guid = R.UserPicGuid ORDER BY PicSize DESC 然后发现Linq中的join不能多条件.. ...

  3. nyoj 14 会场安排问题(贪心专题)

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  4. Stm32 debug停留在"BKPT 0xAB"或者"SWI 0xAB"的解决办法。

    一..背景: 曾经在工作中接触过STM32一段时间,但没有深入的去学习,只是用前辈搭建好的模型来实现一些功能罢了,俗话说的好,大树底下好乘凉,开发确实轻松了,可是不深究点,又觉着心里不踏实,然而也一直 ...

  5. Spark之scala

    一.什么是scala scala 是基于JVMde 编程语言.JAVA是运行在jvm上的编程语言,java 源代码通过jvm被编译成class 文件,然后在os上运行class 文件.scala是运行 ...

  6. 第2月第3天 egorefresh

    egorefresh是很老的下拉刷新,它是一个uiview,在uitableview 下拉的时候显示不同的界面. egorefresh和uitableview的耦合度很高,uitableview滚动和 ...

  7. iOS resign code with App Store profile and post to AppStore

    http://stackoverflow.com/questions/17545452/ios-resign-code-with-app-store-profile-and-post-to-appst ...

  8. JS中的prototype(原文地址:http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html)

    JS中的phototype是JS中比较难理解的一个部分 本文基于下面几个知识点: 1 原型法设计模式 在.Net中可以使用clone()来实现原型法 原型法的主要思想是,现在有1个类A,我想要创建一个 ...

  9. 给groupBox添加滚动条

    public Form3() { InitializeComponent(); foreach (Control gbox in groupBox1.Controls) { if (gbox is V ...

  10. h5上传图片

    1.如何在H5上传图片 使用FileReader 2.FileReader接口 传图片我们只用到readAsDataURL 3.FileReader接口事件 传图片我们只用到onload 4.如何使用 ...