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;
}
 
时间: 2024-10-11 05:20:39

2101 Problem A Snake Filled的相关文章

今天石大比的赛,这道问题 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

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

TJU Problem 2101 Bullseye

注意代码中: result1 << " to " << result2 << ", PLAYER 1 WINS."<< endl; 和 result1 << " to " << result2 << ", PLAYER 1 WINS. "<< endl; 虽然只在WINS后只差一个空格,但会导致PE. 原题: 2101.   Bul

HDU 2101: A + B Problem Too

///@link http://acm.hdu.edu.cn/showproblem.php?pid=2101///@author Sycamore///@date Aug, 16#include<bits/stdc++.h>using namespace std;int main(){ ios::sync_with_stdio(false); cin.tie(0); int A,B; while(cin>>A>>B) cout<<((A+B)%86?&qu

Snake and Ladder Problem

Given a snake and ladder board, find the minimum number of dice throws required to reach the destination or last cell from source or 1st cell. Basically, the player has total control over outcome of dice throw and wants to find out minimum number of

CodeForces 510 A. Fox And Snake(模拟啊 )

题目链接:http://codeforces.com/problemset/problem/510/A Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m

A - Fox And Snake

Problem description Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th

XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondMemory limit: 256 mebibytesAlice and Bob are playing the next game. Both have same matrix N × M filled with digits from 0 to 9.Alice cuts the matrix ve

hdu3699 A hard Aoshu Problem 暴搜

http://acm.hdu.edu.cn/showproblem.php?pid=3699 A hard Aoshu Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 62768/32768 K (Java/Others) Total Submission(s): 968    Accepted Submission(s): 490 Problem Description Math Olympiad is calle