MemSQL start[c]up Round 1.b
二分查找题, 不知道用double的人,用LL果断错了。。。
1 second
256 megabytes
standard input
standard output
Daniel is organizing a football tournament. He has come up with the following tournament format:
- 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.
- 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.
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.
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number:-1.
3
3
4
25
20
2
-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的更多相关文章
- MemSQL start[c]up Round 2 - online version C. More Reclamation(博弈)
题目大意 额,写来写去,我还是直接说抽象之后的题目大意吧: 有一个 r*2 的矩形,两个人轮流的在矩形上面减去一个 1*1 的小正方形,要求在减的过程中,不能使矩形“断开”,也就是说,如果一个人减去了 ...
- MemSQL start[c]up Round 2 - online version(DP)
只有小写字母 那>=2600的直接找单字母串长度大于等于100的就可以了 <2600 的dp找最长回文串 #include <iostream> #include<cst ...
- codeforces MemSQL start[c]up Round 2 - online version B 最长公共子系列
题目链接: http://codeforces.com/contest/335/problem/B 分析: 第一眼看上去串的长度为5*10^4, 冒似只能用O(n)的算法可解. 而这样的算法从来没见 ...
- MemSQL start[c]up Round 1 B题
题目链接 http://codeforces.com/contest/325/problem/B 第一遍写了暴搜,果断TLE 然后上了二分,结果120组数据只有第40组过不了,我就写了奇怪的东西... ...
- MemSQL start[c]up Round 1.E
完全的乱搞题啊... 被坑的要死. 拿到题目就觉得是规律题加构造题, 然后找了了几个小时无果,只知道n为奇数的时候是一定无解的,然后当n为偶数的时候可能有很多解,但是如果乱选择的话,很有可能形成无解的 ...
- 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 ...
- MemSQL Start[c]UP 2.0 - Round 2 - Online Round
搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...
- MemSQL Start[c]UP 2.0 - Round 1
A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...
- MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline (线段的 枚举)
昨天cf做的不好,居然挂零了,还是1点开始的呢.,,, a题少了一个条件,没判断长度. 写一下B题吧 题目链接 题意: 给出(n, m),可以得到一个矩形 让你依次连接矩形内的4个点使它们的长度和最长 ...
随机推荐
- python --subprocess 范例
范例1:查看ipconfig -all命令的输出,并将将输出保存到文件tmp.log中: import subprocess handle = open(r'd:\tmp.log','w') p=su ...
- C#:消息框
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- tp数据库操作
1.常见的数据库操作//插入记录// $insert=Db::execute("insert into tp_user (username,password) values ('dome', ...
- substr.js 字符串切割
substr.js 字符串切割 GitHub 以一个中文字的宽度为一个单位进行字符串切割 substr('南拳的妈妈1992', 4) // => 南拳的妈... substr('imliane ...
- 关于“Could not open ServletContext resource [/WEB-INF/applicationContext.xml]”解决方案
问题说明,我在web.xml文件中进行了如下配置 <servlet> <servlet-name>dispatcherServlet</servlet-name> ...
- RESTful Web Service实战 小结1
1 REST的基本实现形式HTTP+URI+XML,但不是唯一形式.XML后来被Json格式替代.REST是一中架构风格(Representational State Transfer,表述性状态转移 ...
- C++加载dll失败或显示乱码
右键项目-属性-字符集-使用多字节字符集
- WebSocket请求过程分析及实现Web聊天室
WebSocket协议是基于TCP的一种新的协议.WebSocket最初在HTML5规范中被引用为TCP连接,作为基于TCP的套接字API的占位符.它实现了浏览器与服务器全双工(full-duplex ...
- 第八课:不一样的链表 linux链表设计哲学 5星级教程
这一课最后实现的链表,和普通链表不同,借鉴了linux内核链表的思想,这也是企业使用的链表. 基础介绍: 顺序表的思考 顺序表的最大问题是插入和删除需要移动大量的元素!如何解决?A:在线性表数据元素之 ...
- FreeRTOS 中断优先级配置(重要)
以下转载自安富莱电子: http://forum.armfly.com/forum.php NVIC 的全称是 Nested vectored interrupt controller,即嵌套向量中断 ...