Array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Problem 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
 
Source
题目链接:点击传送
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=;
const ll INF=1e18+,mod=;
set<ll>s;
set<ll>::iterator it;
ll dfs(ll n)
{
//cout<<n<<endl;
if(n==) return ;
it=s.find(n);
if(it!=s.end())
return *dfs(n/)+n-n/;
it=s.upper_bound(n);
it--;
ll x=n-(*it);
ll z=(*it);
return dfs(z)+dfs(x-)+n-z;
}
int main()
{
for(int i=;i<;i++)
s.insert((1LL<<i)-);
int T;
scanf("%d",&T);
while(T--)
{
ll n;
scanf("%lld",&n);
ll ans=dfs(n);
printf("%lld\n",ans);
}
return ;
}
 

hdu 5587 Array 二分的更多相关文章

  1. hdu 5587 Array

    题目链接:hdu 5587 前两周 bc 上的题了,因为赶大作业所以没有去打,看了下官方给出的思路,感觉好强大~~竟然能转化成求二进制数 1 的个数: 然后数位 dp 就行了, #include< ...

  2. hdu 5587 Array 数学题

    Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...

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

    Array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Sub ...

  4. 2019年CCPC网络赛 HDU 6703 array【权值线段树】

    题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一 ...

  5. HDU 5587:Array

    Array  Accepts: 118  Submissions: 232  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 131072/ ...

  6. UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)

    UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...

  7. hdu 2413(最大匹配+二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...

  8. HDU 5884 Sort (二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...

  9. hdu 1281棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281   Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...

随机推荐

  1. selenium python 启动Chrome

    启动Chrom浏览器 下载chromedriver: http://chromedriver.storage.googleapis.com/index.html 当时找chromedriver与chr ...

  2. Leetcode: Construct Binary Tree from Preorder and Inorder Transversal

    Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that ...

  3. HDU 1432 Lining Up(几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=1432 题目大意: 2维平面上给定n个点,求一条直线能够穿过点数最多是多少. 解题思路: 因为题目给定的n(1~7 ...

  4. sql server2012重复执行创建表视图sql及带行号的视图

    1.可重复操作(创建表,视图)的sql语句判断 IF EXISTS ( SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[re ...

  5. Hibernate—部分

    数据持久化的3种方式: merge()方法: 先得到对象的副本:再判断, 如果副本为瞬时状态,则用save()插入 如果副本为游离状态,则用update()更新 最终都是不改变传入对象的状态 save ...

  6. 有关padding的二三事~~

    浏览器支持 所有浏览器都支持 padding 属性. 注释:任何的版本的 Internet Explorer (包括 IE8)都不支持属性值 "inherit". 定义和用法 pa ...

  7. ServiceStack DotNet Core前期准备

    下载DotNet Core SDK 下载地址:https://dotnet.microsoft.com/download. 安装完成之后通过cmd的命令行进行确认. 官方自带的cmd比较简陋,可以用c ...

  8. AdaBoost学习笔记

    学习了李航<统计学习方法>第八章的提升方法,现在对常用的一种提升方法AdaBoost作一个小小的笔记,并用python实现书本上的例子,加深印象.提升方法(boosting)是一种常用的统 ...

  9. Python 基本数据类型(2)

    知识内容: 1.python对象模型 2.数字与bool 3.字符串 4.列表与元组 5.字典与集合 一.python对象模型 1.python对象模型 对象是python语言中最基本的概念,在pyt ...

  10. Jmeter响应内容显示乱码问题的解决办法

    Jmeter在访问接口的时候,响应内容如果有中文可能会显示乱码,原因应该是响应页面没有做编码处理,jmeter默认按照ISO-8859-1编码格式进行解析. 下面把解决步骤列一下: 现象:jmeter ...