题目:B. Stadium and Games

分析:问题可以转化为下面的等式求解问题:

由于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(二分搜索)的更多相关文章

  1. [LeetCode] Largest BST Subtree 最大的二分搜索子树

    Given a binary tree, find the largest subtree which is a Binary Search Tree (BST), where largest mea ...

  2. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  3. hdu 2199:Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  4. 二分搜索 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.注意会爆 ...

  5. hdu 1075 二分搜索

    还是写一下,二分搜索好了 这道题开数组比较坑... 二分,需要注意边界问题,例如:左闭右闭,左闭右开,否则查找不到or死循环 先上AC代码 #include<iostream> #incl ...

  6. K Best(最大化平均数)_二分搜索

    Description Demy has n jewels. Each of her jewels has some value vi and weight wi. Since her husband ...

  7. HDU 2852 KiKi's K-Number(树状数组+二分搜索)

    题意:给出三种操作 0 e:将e放入容器中 1 e:将e从容器中删除,若不存在,则输出No Elment! 2 a k:搜索容器中比a大的第k个数,若不存在,则输出Not Find! 思路:树状数组+ ...

  8. nyoj914Yougth的最大化(二分搜索 + 贪心)

    Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗 ...

  9. 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 ...

  10. poj3579 二分搜索+二分查找

    Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5468   Accepted: 1762 Descriptio ...

随机推荐

  1. CSS简介和CSS选择器

    <pre name="code" class="html">Css 简洁 css 选择器 标签选择器 类选择器 ID选择器 Css 层叠样式表 Ca ...

  2. Java 螺纹第三版 第三章数据同步 读书笔记

    多线程间共享数据问题 一.Synchronizedkeyword      atomic一词与"原子"无关,它以前被觉得是物质的最小的单元,不能再被拆解成更小的部分.      当 ...

  3. Perl 5 教程

    Perl 5 教程 http://www.cbi.pku.edu.cn/chinese/documents/perl/index.htm

  4. 基于visual Studio2013解决C语言竞赛题之1021九九乘法表

         题目 解决代码及点评 /* 功能:请编程序按如下格式打印一个直角三角形的九九乘法表: 1 2 3 4 5 6 7 8 9 4 6 8 10 12 14 16 18 9 1 ...

  5. boost之program_options库,解析命令行参数、读取配置文件

    一.命令行解析 tprogram_options解析命令行参数示例代码: #include <iostream> using namespace std; #include <boo ...

  6. 施用 maven shade plugin 解决 jar 或类的多版本冲突

    施用 maven shade plugin 解决 jar 或类的多版本冲突   使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...

  7. perl post发送json数据

    sub  wx_init {                #$login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=- ...

  8. 基于visual Studio2013解决面试题之0710求方优化

     题目

  9. scrum经验

    Scrum是基于过程控制理论的经验方法,倡导自组织团队:其运行框架核心是迭代增量型并行开发,也是“适应性”的软件开发方法.Scrum提供了高度可视化的用于管理软件开发复杂性管理的敏捷项目管理的实践框架 ...

  10. android JSON数据格式 解析

    一.   JSON (JavaScript Object Notation)一种简单的数据格式,比xml更轻巧.  Json建构于两种结构:  最后再加一种格式在文章的最后显示出来非常少有的格式   ...