题目描述

“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. 8-Highcharts曲线图之对数直线图

    <!DOCTYPE> <html lang='en'> <head> <title>8-Highcharts曲线图之对数直线图</title> ...

  2. oracle删除表以及清理表空间

    若要彻底删除表,则使用语句:drop table <table_name> purge; 清除回收站里的信息 清除指定表:purge table <table_name>; 清 ...

  3. 【PHP面向对象(OOP)编程入门教程】2.什么是类,什么是对象,类和对象这间的关系

    类的概念:类是具有相同属性和服务的一组对象的集合.它为属于该类的所有对象提供了统一的抽象描述,其内部包括属性和服务两个主要部分.在面向对象的编程语言中,类是一个独立的程序单位,它应该有一个类名并包括属 ...

  4. iOS设备 屏幕尺寸、操作系统、摄像头像素、发行时间 汇总

    设备 硬件尺寸 软件尺寸 精密程度 操作系统 摄像头像素 发行时间 iPhone 4s 640 x 960 320 x 480 2x iOS 5 800万 2011.10.04 iPhone 5 64 ...

  5. github 上传至远程的过程

    参考网址:http://luolei.org/dotfiles-tutorial/ http://www.ruanyifeng.com/blog/2014/06/git_remote.html     ...

  6. java之远程接口调用

    一.通过地址栏传值 1.项目结构 2.pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...

  7. iOS开发初级课程

    iOS开发初级课程 针对学员 掌握Objective  C,C或者C++,有语言基础的学员,想从事iOS开发工作. iOS开发那些事-了解iOS开发(8集) 在课程中,我们首先介绍如何使用nib和故事 ...

  8. CSU 1113 Updating a Dictionary(map容器应用)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...

  9. C 语言 typedef

    虽然#define语句看起来象typedef,但实际上却有本质上的差别.对于#define来说,仅在编译前对源代码进行了字符串替换处理:而对于typedef来说,它建立了一个新的数据类型别名.由此可见 ...

  10. nhibernat4.0.0.4000 bug

    //类 NHibernate.Loader.Loader 中 protected virtual string[] ResultRowAliases { get { return null; } } ...