2018/2/2牛客网挑战参赛C题 列一列。。。。。。。

链接:https://www.nowcoder.com/acm/contest/71/C
来源:牛客网

题目描述
小W在计算一个数列{An},其中A1=1,A2=2,An+2=An+1+An。尽管他计算非常精准,但很快他就弄混了自己的草稿纸,他找出了一些他计算的结果,但他忘记了这些都是数列中的第几项。
输入描述:

每行包括数列中的一项Ak(k<=100000)。

总行数T<=30。

输出描述:

对于每一项Ak,输出一行包括一个正整数k表示输入中数是数列的第几项。

示例1
输入

2
3
5
8
13

输出

2
3
4
5
6

破题。。。。卡我半天。。。。

ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ull unsigned long long

using namespace std;

unsigned long long s[100003];
map<unsigned long long, int> mp;
int n;
unsigned long long t;
char str[100003];
inline unsigned long long getnum()
{
    int pos=0;
    long long now=0;char ch=str[pos++];
    while(ch>='0' && ch<='9'){now=(now<<3)+(now<<1)+ch-'0';ch=str[pos++];}
    return now;
}
int main()
{
    s[1]=1;
    s[2]=2;
    mp[2]=2;
    mp[1]=1;
    for (int i=3;i<=100000;i++)
    {
        s[i]=(s[i-1]+s[i-2]);
        mp[s[i]]=i;
    }
    while (scanf("%s",str)!=EOF) printf("%d\n",mp[getnum()]);
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值