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的棋盘, ...
随机推荐
- git 生成patch 和打入patch
转载:https://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用gi ...
- 微信小程序----团购或秒杀的批量倒计时实现
效果图 实现思路微信小程序实现倒计时,可以将倒计时的时间进行每一秒的计算和渲染! JS模拟商品列表数据 goodsList:在 onLoad 周期函数中对活动结束时间进行提取:建立时间格式化函数 ti ...
- How to enable TLS 1.2 on Windows Server 2008 R2
Problem How to enable TLS 1.2 on Windows Server 2008 R2? Resolution QuoVadis recommends enabling and ...
- C#读取Excel,Access数据库
出自:http://blog.csdn.net/limpire/article/details/2599760 使用 OpenRowSet 和 OpenDataSource 访问 Excel 97-2 ...
- 002-ubuntu安装
一.安装了ubuntu desktop版本后: 1.进行桥接联网. 2.运行更新:#sudo apt-get update. 3.安装net-tools网络工具包:#sudo apt install ...
- EBS 多组织访问设置
如果想让你的职责下为单组织模式,那么你在Profile下只设置MO: Operating Unit的值,MO: Operating Unit提供只访问一个单独的OU.如果你想让你的职责下为多组织模式, ...
- 用python实现一个简单的socket网络聊天通讯 (Linux --py2.7平台与windows--py3.6平台)
windows --> windows 写法均在py3.6 客户端写法 import socket client = socket.socket() client.connect(('192 ...
- Rpgmakermv(5) MiniLabel插件介绍
============================================================================ Introduction ========== ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON SetComprise2
zw版[转发·台湾nvp系列Delphi例程]HALCON SetComprise2 procedure TForm1.Button1Click(Sender: TObject);var op : H ...
- 2016-2017-2 《Java程序设计》第5周学习总结
学号 2016-2017-2 <Java程序设计>第5周学习总结 教材部分学习内容总结 第八章: 一.语法与继承架构 使用try.catch: •执行流程 1.尝试执行try区块中程序代码 ...