ACdream 1020 The Game about KILL

本文介绍了一种通过预计算特定数列的值来快速解决一类数列求值问题的算法。该算法首先生成数列的前缀和,然后利用这些前缀和快速查找并返回任意给定点的数列值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

找规律。

1
1 3 
1 3 5 7
1 3 5 7 9 11 13 15

.......

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}

const int maxn=40;
LL a[maxn],b[maxn];

int main()
{
    a[1]=1; b[0]=0;
    for(int i=2;i<=31;i++) a[i]=2*a[i-1];
    for(int i=1;i<=31;i++) b[i]=b[i-1]+a[i];
    LL n;

    while(~scanf("%lld",&n))
    {
        for(int i=1;i<=31;i++)
        {
            if(b[i]<=n) continue;
            else
            {
                LL x=n-b[i-1]; if(x==0) x=a[i-1];
                printf("%lld\n",1+(x-1)*2);
                break;
            }
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/zufezzt/p/5782033.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值