二分查找题, 不知道用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
  1. 3
output
  1. 3
    4
input
  1. 25
output
  1. 20
input
  1. 2
output
  1. -1
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <map>
  7. #include <queue>
  8. #include <sstream>
  9. #include <iostream>
  10. using namespace std;
  11. #define INF 0x3fffffff
  12. //#define __int64 long long int
  13. typedef __int64 LL;
  14.  
  15. LL save[];
  16. int cont[];
  17.  
  18. double mabs(double x)
  19. {
  20. if(x<) x*=-1.0;
  21. return x;
  22. }
  23.  
  24. //用double来判断是否这种中途运算过程可能超出LL的,但是每个结果相差比较的的情况,是非常好用的,比用大数方便
  25.  
  26. int main()
  27. {
  28. //freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
  29. //freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
  30. LL n;
  31. cin>>n;
  32. LL tmp=;
  33. int flag=;
  34. int cnt=;
  35. for(int i=;i<;i++)
  36. {
  37. LL k=tmp-;
  38. if(k > n) break;
  39. tmp *= ;
  40. LL b=,d=n,mid;
  41. flag=;
  42. while(b<=d)
  43. {
  44. mid=(b+d)/;
  45. if( mabs(mid*mid*1.0+1.0*mid*(*k-) - 2.0*n)<1e-)
  46. {
  47. flag=;
  48. break;
  49. }
  50. if(1.0*mid*mid+1.0*mid*(*k-)>2.0*n)
  51. d=mid-;
  52. else b=mid+;
  53. }
  54. if(flag==&&(mid)%!=)
  55. save[cnt++] = (mid*tmp/);
  56. }
  57. sort(save,save+cnt);
  58. if(cnt==)
  59. printf("-1\n");
  60. else
  61. for(int i=;i<cnt;i++)
  62. cout<<save[i]<<endl;
  63. return ;
  64. }

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. 工作总结 表单提交中 Input 设置 disabled readonly

    input框里面添加disabled属性之后,该内容就无法向上提交  需要的时候也可以再移除disabled readonly这个属性来禁止用户修改, 可以正常提交. Hiddent 隐藏  也可以正 ...

  2. unity5,UI Button too small on device than in Game View解决办法

    假设测试设备为iphone5(横屏).下面说明如何使真机上ui显示效果与Game View中一致. 1,首先Game View左上角屏幕规格选 iPhone 5 Wide (16:9),如图: 2,在 ...

  3. POJ 1321:棋盘问题

    棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21666   Accepted: 10765 Descriptio ...

  4. MySQL存储过程使用实例详解

    本文介绍关于在MySQL存储过程游标使用实例,包括简单游标使用与游标循环跳出等方法 例1.一个简单存储过程游标实例 DROP PROCEDURE IF EXISTS getUserInfo $$CRE ...

  5. c++创建一个char数组

    char c[] = { 'a', 'b', 'c', '\0' }; char* cp = c; printf(cp); 所有的char类型都以'\0'结尾

  6. Atitit.网页爬虫的架构总结

    Atitit.网页爬虫的架构总结 1. 总数的结构..(接口方法) 1 2. 获得页数 1 3. 跳页处理(接口方法) 2 4. 单个的页面处理(接口方法) 2 4.1. 获得页面url 3 4.2. ...

  7. java synchronized究竟锁住的是什么

    刚学java的时候,仅仅知道synchronized一个线程锁.能够锁住代码,可是它真的能像我想的那样,能够锁住代码吗? 在讨论之前先看一下项目中常见关于synchronized的使用方法: publ ...

  8. Js 省市联动

    function cn(){ this.Items = {}; } cn.prototype.add = function(id,iArray){ this.Items[id] = iArray; } ...

  9. (转载)C++STL中vector容器的用法

     vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector之所以被认为是一个容器,是因为它能够像容器一样存放各种类型的对象,简单地说vec ...

  10. ubuntu server执行sudo出现"no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory"

    [Ubuntu] 執行 sudo 時,出現 "no talloc stackframe at ../source3/param/loadparm.c:4864, leaking memory ...