hdu 5587 Array 数学题

Array

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5587

Description

Vicky is a magician who loves math. She has great power in copying and creating.
One day she gets an array {1}。 After that, every day she copies all the numbers in the arrays she has, and puts them into the tail of the array, with a signle ‘0‘ to separat.
Vicky wants to make difference. So every number which is made today (include the 0) will be plused by one.
Vicky wonders after 100 days, what is the sum of the first M numbers.

Input

There are multiple test cases.
First line contains a single integer T, means the number of test cases.(1≤T≤2∗103)
Next T line contains, each line contains one interger M. (1≤M≤1016)

Output

For each test case,output the answer in a line.

Sample Input

3 1 3 5

Sample Output

1 4 7

HINT

题意

题解:

数学题(:

首先我们先用找规律算出第i天一共能得到的和是多少:g(i)=g(i-1)+2^(i-1)

然后我们就可以递归求解了,不断地利用2的幂来进行递归

代码:

#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;

vector<long long>Q;
long long ans = 0;
long long g[230];
void solve(long long k)
{
    if(k<=0)return;
    int p = --upper_bound(Q.begin(),Q.end(),k)-Q.begin();
    ans+=g[p]+k-Q[p];
    solve(k-Q[p]-1);
}
int main()
{

    long long T=2;
    Q.push_back(0);
    for(int i=1;i<=59;i++)
    {
        Q.push_back(T-1);//2^i-1
        T*=2;
    }
    g[1]=1;long long tmp=2;
    for(int i=2;i<=Q.size();i++)
    {
        g[i]=2*g[i-1]+tmp;//存的是第i天的答案
        tmp=tmp*2;
    }
    int t;scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        long long x;scanf("%I64d",&x);
        ans = 0;
        solve(x);
        printf("%I64d\n",ans);
    }
}
时间: 2024-10-10 10:11:05

hdu 5587 Array 数学题的相关文章

HDU 5587——Array——————【规律】

Array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 417    Accepted Submission(s): 211 Problem Description Vicky is a magician who loves math. She has great power in copying and creating.One

hdu 6197 array array array

http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你一个数组 然后给你一个k  让你从数组里面剔除k个数  使得剩余的数组 是 单调非递减  或 单调非递增的 判断可不可能 思路 : 直接写LIS  然后判断 n-k 和 LIS 长度的大小关系 #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+100; const int INF = 0x3f3f3f3f; i

HDU 1018(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1018 Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27548    Accepted Submission(s): 12526 Problem Description In many applications ve

HDU 6197 array array array 2017沈阳网络赛 LIS

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增序列 解法:签到题,就是让你求最长不下降子序列长度len,然后判断下n-len是否小于k(将序列反着存下来然后再求即最长不上升子序列,取两者len中的较大值),然后直接套nlogn的模板即可. #include <bits/stdc++.h> using namespace std; const

HDU 6467 简单数学题 【递推公式 &amp;&amp; O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 308    Accepted Submission(s): 150 Problem Description 已知 F(n)=∑i=1n(i×∑j=inCij) 求 F(n) m

HDU - 6197 array array array (最长上升子序列&amp;最长下降子序列)

题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n". 分析: 1.求一遍LCS,然后在将序列逆转,求一遍LCS,分别可得最长上升子序列和最长下降子序列的长度tmp1.tmp2. 2.n - tmp1 <= k或n - tmp2 <= k即可,需要去掉的去完之后,在已经是最长上升或最长下降的序列中随便去够k个就好了. #include<

第十场 hdu 6172 Array Challenge(矩阵快速幂)

http://acm.hdu.edu.cn/showproblem.php?pid=6172 题目大意:按照给出的公式算出an 解题思路:an=4an-1+17an-2-12an-3,不要问我为什么,我也不知道(?_?) AC代码: 1 #include <iostream> 2 #include<bits/stdc++.h> 3 //if(~i)//当i不是-1时满足条件 4 using namespace std; 5 const int SMod=1e9+7; 6 struc

2017多校第10场 HDU 6172 Array Challenge 猜公式,矩阵幂

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172 题意:如题. 解法: #include <bits/stdc++.h> using namespace std; typedef long long LL; const LL mod = 1e9+7; struct Matrix{ LL a[3][3]; void set1(){ memset(a, 0, sizeof(a)); } void set2(){ memset(a, 0, siz

hdu 6197 array array array LIS

正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件. ac代码: #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <map> #include <stack> #include <algorithm> using namespace std; int dp[1001]; int LIS(int a