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个点使它们的长度和最长 ...
随机推荐
- mysql 用户自定义变量
SQL中可以用变量来操作值.那么问题就来了.mysql中怎么定义一个变量呢? 一.定义变量 1.定义变量的语法: set @var_name=expr [,@var_name=expr] ... 2. ...
- springmvc mybatis 声明式事务管理回滚失效,(checked回滚)捕捉异常,传输错误信息
一.知识点及问题 后端框架: Spring .Spring mvc .mybatis 业务需求: client先从服务端获取用户大量信息到client,编辑完毕之后统一Post至服务端,对于数据的改动 ...
- atitit.窗体静听esc退出本窗体java swing c# .net php
atitit.窗体静听esc退出本窗体java swing c# .net php 1. 监听esc 按键 1 1.1. 监听一个组件 1 1.2. 监听加在form上 1 2. 关闭窗体 2 1. ...
- 【Android】15.5 例15-3—Notification的各种属性演示
分类:C#.Android.VS2015: 创建日期:2016-02-29 一.简介 利用这个例子,可测试通知的各种属性以及这些不同属性选项呈现的效果. 另外,在这个例子中,还演示了如何读写SD中的图 ...
- vue-cli 中实现简单动画效果 (vue2.0)
1,写一个简单的headcomp组件如下: <template> <div class="box"> <transition name="m ...
- 区别:Use MFC In A Shared DLL 和 Use MFC In A Static Library
摘自:Programming Windows with MFC, 2nd Edition Choosing Use MFC In A Shared DLL minimizes your applica ...
- rpc 理解
RPC=Remote Produce Call 是一种技术的概念名词. HTTP是一种协议,RPC可以通过HTTP来实现,也可以通过Socket自己实现一套协议来实现. rpc是一种概念,http也是 ...
- JAVA判断字符串相等
java中判断字符串是否相等有两种方法:1.用“==”运算符,该运算符表示指向字符串的引用是否相同,比如: String a="abc";String b="abc&qu ...
- 一款基于jQuery和CSS3炫酷3D旋转画廊特效插件
这是一款效果炫酷的jQuery和CSS3 3D旋转画廊特效插件.该3D画廊插件可以通过前后导航按钮来切换图片,效果就像旋转木马一样.它还带有点击放大图片,显示图片标题和用键盘操作等功能. 在线预览 ...
- renderer:function参数介绍
转载自:http://blog.sina.com.cn/s/blog_9eaf28f90101b7y3.html renderer:function(value, cellmeta, record, ...