Codeforces325-B(二分搜索)
分析:问题可以转化为下面的等式求解问题:
由于n在10^18范围内,所以k的范围是从0到63即可,这样就可以枚举k,二分m,然后所有符合条件的就是答案了。
注意这里数据范围的处理,不注意的话就会溢出的。
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h> using namespace std;
typedef long long LL; LL a[100005];
LL c; void Solve(LL n)
{
LL k;
for(k=0;k<63;k++)
{
LL l=1,r=3*1e9;
if(k>=30) r=1000000000000000000>>k;
while(l<=r)
{
LL mid=(l+r)>>1;
LL ans=(((LL)1<<k)-1)*mid*2+mid*(mid-1);
if(ans>2*n) r=mid-1;
else if(ans<2*n) l=mid+1;
else
{
if(mid&1) a[c++]=mid*((LL)1<<k);
break;
}
}
}
} int main()
{
LL n,i;
while(cin>>n)
{
c=0;
Solve(n);
sort(a,a+c);
if(c==0) puts("-1");
else
{
for(i=0;i<c;i++)
cout<<a[i]<<endl;
}
}
return 0;
}
Codeforces325-B(二分搜索)的更多相关文章
- [LeetCode] Largest BST Subtree 最大的二分搜索子树
Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 2199:Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 二分搜索 UVALive 6076 Yukari's Birthday (12长春K)
题目传送门 题意:问使得sum (k^i) = n || n -1 (1 <= i <= r) 的min (r*k)组合的r和k 分析:r的最大不会超过40,枚举r,二分搜索k.注意会爆 ...
- hdu 1075 二分搜索
还是写一下,二分搜索好了 这道题开数组比较坑... 二分,需要注意边界问题,例如:左闭右闭,左闭右开,否则查找不到or死循环 先上AC代码 #include<iostream> #incl ...
- K Best(最大化平均数)_二分搜索
Description Demy has n jewels. Each of her jewels has some value vi and weight wi. Since her husband ...
- HDU 2852 KiKi's K-Number(树状数组+二分搜索)
题意:给出三种操作 0 e:将e放入容器中 1 e:将e从容器中删除,若不存在,则输出No Elment! 2 a k:搜索容器中比a大的第k个数,若不存在,则输出Not Find! 思路:树状数组+ ...
- nyoj914Yougth的最大化(二分搜索 + 贪心)
Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗 ...
- poj 2976 Dropping tests (二分搜索之最大化平均值之01分数规划)
Description In a certain course, you take n tests. If you get ai out of bi questions correct on test ...
- poj3579 二分搜索+二分查找
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5468 Accepted: 1762 Descriptio ...
随机推荐
- 从底层简析Python程序的执行过程
摘要:是否想在Python解释器的内部晃悠一圈?是不是想实现一个Python代码执行的追踪器?没有基础?不要怕,这篇文章让你初窥Python底层的奥妙. [编者按]下面博文将带你创建一个字节码级别的追 ...
- 获取证书以用于 Windows Azure 网站 (WAWS)
编辑人员注释:本文章由 Windows Azure 网站团队的项目经理 Erez Benari 撰写. 近年来,随着网络犯罪的上升,使用 SSL 保护网站逐渐成为一项备受追捧的功能,Windows A ...
- AV_百度百科
AV_百度百科 AV(影片门类)
- hdu 4771 Stealing Harry Potter's Precious(bfs)
题目链接:hdu 4771 Stealing Harry Potter's Precious 题目大意:在一个N*M的银行里,贼的位置在'@',如今给出n个宝物的位置.如今贼要将全部的宝物拿到手.问最 ...
- 【Bootstrap3.0建站笔记一】表单元素排版
1.文字和输入框前后排列: 代码: <div class="row"> <div class="col-lg-12"> <div ...
- 不可表示的数[x/2] + y + x * y
前端是时间在庞果网上看到不可表示的数的编程题(如下),我自己也试着解答了一下,写的算法虽然没有没有错,但是跑了一些还只是跑到a8,后来到自己整理一下网上的解答过程,虽然解答写的很清晰,但是有些知识还是 ...
- 重新签名apk文件(手工用命令行)
re-sign.jar中后自动去除签名这个方法,经试验不可用! 1.去除准备重新签名SinaVoice.apk软件本身的签名 将apk文件后缀改为.zip,然后从winrar中删除META-INF文件 ...
- Perl 面向对象编程的两种实现和比较:
<pre name="code" class="html">https://www.ibm.com/developerworks/cn/linux/ ...
- How to decompile class file in Java and Eclipse - Javap command example(转)
Ability to decompile a Java class file is quite helpful for any Java developer who wants to look int ...
- UVA 10911 Forming Quiz Teams(dp + 集合最优配对问题)
4th IIUC Inter-University Programming Contest, 2005 G Forming Quiz Teams Input: standard input Outpu ...