二分查找题, 不知道用double的人,用LL果断错了。。。

B. Stadium and Games
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Daniel is organizing a football tournament. He has come up with the following tournament format:

  1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even.
  2. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be  games), and the tournament ends.

For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.

Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.

Input

The first line contains a single integer n (1 ≤ n ≤ 1018), the number of games that should be played.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.

Output

Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number:-1.

Sample test(s)
input
3
output
3
4
input
25
output
20
input
2
output
-1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff
//#define __int64 long long int
typedef __int64 LL; LL save[];
int cont[]; double mabs(double x)
{
if(x<) x*=-1.0;
return x;
} //用double来判断是否这种中途运算过程可能超出LL的,但是每个结果相差比较的的情况,是非常好用的,比用大数方便 int main()
{
//freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
//freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
LL n;
cin>>n;
LL tmp=;
int flag=;
int cnt=;
for(int i=;i<;i++)
{
LL k=tmp-;
if(k > n) break;
tmp *= ;
LL b=,d=n,mid;
flag=;
while(b<=d)
{
mid=(b+d)/;
if( mabs(mid*mid*1.0+1.0*mid*(*k-) - 2.0*n)<1e-)
{
flag=;
break;
}
if(1.0*mid*mid+1.0*mid*(*k-)>2.0*n)
d=mid-;
else b=mid+;
}
if(flag==&&(mid)%!=)
save[cnt++] = (mid*tmp/);
}
sort(save,save+cnt);
if(cnt==)
printf("-1\n");
else
for(int i=;i<cnt;i++)
cout<<save[i]<<endl;
return ;
}

MemSQL start[c]up Round 1.b的更多相关文章

  1. MemSQL start[c]up Round 2 - online version C. More Reclamation(博弈)

    题目大意 额,写来写去,我还是直接说抽象之后的题目大意吧: 有一个 r*2 的矩形,两个人轮流的在矩形上面减去一个 1*1 的小正方形,要求在减的过程中,不能使矩形“断开”,也就是说,如果一个人减去了 ...

  2. MemSQL start[c]up Round 2 - online version(DP)

    只有小写字母 那>=2600的直接找单字母串长度大于等于100的就可以了 <2600 的dp找最长回文串 #include <iostream> #include<cst ...

  3. codeforces MemSQL start[c]up Round 2 - online version B 最长公共子系列

    题目链接:  http://codeforces.com/contest/335/problem/B 分析: 第一眼看上去串的长度为5*10^4, 冒似只能用O(n)的算法可解. 而这样的算法从来没见 ...

  4. MemSQL start[c]up Round 1 B题

    题目链接 http://codeforces.com/contest/325/problem/B 第一遍写了暴搜,果断TLE 然后上了二分,结果120组数据只有第40组过不了,我就写了奇怪的东西... ...

  5. MemSQL start[c]up Round 1.E

    完全的乱搞题啊... 被坑的要死. 拿到题目就觉得是规律题加构造题, 然后找了了几个小时无果,只知道n为奇数的时候是一定无解的,然后当n为偶数的时候可能有很多解,但是如果乱选择的话,很有可能形成无解的 ...

  6. MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)

    http://codeforces.com/contest/452/problem/B   B. 4-point polyline time limit per test 2 seconds memo ...

  7. MemSQL Start[c]UP 2.0 - Round 2 - Online Round

    搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...

  8. MemSQL Start[c]UP 2.0 - Round 1

    A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...

  9. MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline (线段的 枚举)

    昨天cf做的不好,居然挂零了,还是1点开始的呢.,,, a题少了一个条件,没判断长度. 写一下B题吧 题目链接 题意: 给出(n, m),可以得到一个矩形 让你依次连接矩形内的4个点使它们的长度和最长 ...

随机推荐

  1. 类型转换运算符、*运算符重载、->运算符重载、operator new 和 operator delete

    一.类型转换运算符 必须是成员函数,不能是友元函数 没有参数 不能指定返回类型 函数原型:operator 类型名();  C++ Code  1 2 3 4 5 6 7 8 9 10 11 12 1 ...

  2. 【Arduino】超声波模块(HC-SR04)

    还好,这个模块有现成的库能够用: https://github.com/bosgood/arduino-playground/tree/master/lib/HCSR04Ultrasonic 下面仅仅 ...

  3. 不止是联网!教你玩转PC自带Wi-Fi网卡

    前言:Wi-Fi对于现在的智能手机来说已经是再熟悉不过的配置了,而主板自带Wi-Fi网卡的设计也越来越普及,但有些玩家可能思维还停留在“Wi-Fi网卡 = 连无线网络用的网卡,我用有线就不需要”的层次 ...

  4. python 操作redis之——HyperLogLog (八)

    #coding:utf8 import redis # python 操作redis之——HyperLogLog r =redis.Redis(host=") # 1.Pfadd 命令将所有 ...

  5. jsp常用标签和标签库及javaBean规范

    1 常用标签forward,pararm,include <jsp:forward page=""></jsp:forward> <jsp:param ...

  6. 详解登录认证及授权--Shiro系列(一)

    Apache Shiro 是一个强大而灵活的开源安全框架,它干净利落地处理身份认证,授权,企业会话管理和加密.Apache Shiro 的首要目标是易于使用和理解.安全有时候是很复杂的,甚至是痛苦的, ...

  7. 【Android】14.2 外部文件存储和读取

    分类:C#.Android.VS2015: 创建日期:2016-02-27 一.简介 1.基本概念 内部存储的私有可用存储空间一般都不会很大,对于容量比较大的文件,例如视频等,应该将其存储在外部存储设 ...

  8. 判断是否是IE浏览器和是否是IE11

    判断是否是IE浏览器用下面这个函数, function isIE() { //ie? 是ie返回true,否则返回false if (!!window.ActiveXObject || "A ...

  9. cocos2d-x 2.0通过CCAnimation实例获取CCSpriteFrame

    通过CCAnimation实例获取CCSpriteFrame,会出现类型转换问题.我们在创建一个animation的时候,经常遵循下面的步骤:1)create 一个CCArray对象A.2)通过A-& ...

  10. Scanner.findInLine()与while的使用莫名其妙的导致NoSuchElementException: No line found

    public static boolean parseHTML(Scanner sc, List<String> errorInfo) { String[] tags = new Stri ...