hdu 5587 Array 二分
Array
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
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.
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)
1
3
5
4
7
#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 二分的更多相关文章
- hdu 5587 Array
题目链接:hdu 5587 前两周 bc 上的题了,因为赶大作业所以没有去打,看了下官方给出的思路,感觉好强大~~竟然能转化成求二进制数 1 的个数: 然后数位 dp 就行了, #include< ...
- hdu 5587 Array 数学题
Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5587 De ...
- HDU 5587——Array——————【规律】
Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Sub ...
- 2019年CCPC网络赛 HDU 6703 array【权值线段树】
题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一 ...
- HDU 5587:Array
Array Accepts: 118 Submissions: 232 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/ ...
- UVA 10816 + HDU 1839 Dijstra + 二分 (待研究)
UVA 题意:两个绿洲之间是沙漠,沙漠的温度不同,告诉起点,终点,求使得从起点到终点的最高温度最小的路径,如果有多条,输出长度最短的路径: 思路:用最小费用(最短路径)最大流(最小温度)也能搞吧,但因 ...
- hdu 2413(最大匹配+二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2413 思路:由于要求最少的时间,可以考虑二分,然后就是满足在limit时间下,如果地球战舰数目比外星战 ...
- HDU 5884 Sort (二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...
- hdu 1281棋盘游戏(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 Problem Description 小希和Gardon在玩一个游戏:对一个N*M的棋盘, ...
随机推荐
- modelform和modelserializer
modelform modelform比form强悍很多
- [py]一些搜集到的问题
过滤爬虫爬取下来的关键字 v1,来不及了,先上车 content = ['哈士奇', '二哈', '哈士奇图片','哈士奇图片', '哈士奇美丽价格', '哈士奇是个大傻逼', '猫咪图片', '猫咪 ...
- Bellon(多么痛的领悟)
尼玛 我今天刚刚知道什么是负权回路 任意相连的无向图之间都是回路!!! 囧了一天了,算是看出来了,渣比 A====B 则A能到B且B能到A,这就是一个回路.
- Ubuntu 16.04下deb文件的安装
pkg 是Debian Package的简写,是为Debian 专门开发的套件管理系统,方便软件的安装.更新及移除.所有源自Debian的Linux发行版都使用dpkg,例如Ubuntu.Knoppi ...
- [LeetCode] 193. Valid Phone Numbers_Easy tag: Bash
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- char* a与char a[]的区别
char *a 与char a[] 的区别 char *a = "hello" 中的a是指向第一个字符‘a'的一个指针 char a[20] = "hello&quo ...
- Qt界面控件值获取异常处理
情景简述: 正常情况,我们从控件获取的值是OK的,但有时候就是奇怪的不对头,那么我们可以给获取后的值加上一个不痛不痒的函数,再返回,结果就OK了.至于原因嘛,[呲牙][呲牙] 比如: //正常情况 d ...
- LeetCode-MinimumDepthOfBinaryTree
题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...
- python+Django框架运用(四)
Django后台管理 基本配置 默认登录地址:http://127.0.0.1:8000/admin 创建后台管理员: python3 ./manage.py createsuperuser # ...
- python堆排序
堆是完全二叉树 子树是不相交的 度 节点拥有子树的个数 满二叉树: 每个节点上都有子节点(除了叶子节点) 完全二叉树: 叶子结点在倒数第一层和第二层,最下层的叶子结点集中在树的左部 ,在右边的话,左子 ...