[codeforces 325]B. Stadium and Games

时间:2022-01-19 02:05:05

[codeforces 325]B. Stadium and Games

试题描述

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 [codeforces 325]B. Stadium and Games 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.

输入示例


输出示例


数据规模及约定

见“输入

题解

不妨设队伍的数量是 2k·m,那么可以得到方程:

[codeforces 325]B. Stadium and Games

左边是个等比数列,代入公式得到:

[codeforces 325]B. Stadium and Games

枚举 k,不难发现这是一个关于 m 的一元二次方程,然后求判别式解方程就好了。

注意过程中可能爆 long long,不过我们有 long double。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;
#define LL long long const int BufferSize = 1 << 16;
char buffer[BufferSize], *Head, *Tail;
inline char Getchar() {
if(Head == Tail) {
int l = fread(buffer, 1, BufferSize, stdin);
Tail = (Head = buffer) + l;
}
return *Head++;
}
LL read() {
LL x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
} #define maxn 70
#define LD long double
LL n, bns[maxn];
int cnt, dnt;
LD sum, t, m, der, ans[maxn];
const LD eps = 1e-30; int main() {
n = read(); sum = 1.0;
for(int i = 0; i <= maxn - 5; i++, sum *= 2.0) {
t = sum - 1.0;
der = 4.0 * t * t - 4.0 * t + 1.0 + (LD)8.0 * (LD)n;
m = (-2.0 * t + 1.0 + sqrt(der)) / 2.0;
if(m - (LD)((LL)m) <= eps && ((LL)m & 1ll) && m - 0.0 >= eps) ans[++cnt] = (LD)((LL)m) * sum;
}
if(!cnt) return puts("-1"), 0;
bns[++dnt] = (LL)ans[1];
for(int i = 2; i <= cnt; i++) if(ans[i] != ans[i-1]) bns[++dnt] = (LL)ans[i]; bool ok = 0;
for(int i = 1; i <= dnt; i++) {
LL x = bns[i];
long double sum = 0.0;
while(!(x & 1)) x >>= 1, sum += (long double)x;
sum += ((long double)x * (x - 1) / 2.0);
if(sum == n) printf("%I64d\n", bns[i]), ok = 1;
}
if(!ok) puts("-1"); return 0;
}

[codeforces 325]B. Stadium and Games的更多相关文章

  1. Codeforces 455B A Lot of Games&lpar;字典树&plus;博弈&rpar;

    题目连接: Codeforces 455B A Lot of Games 题目大意:给定n.表示字符串集合. 给定k,表示进行了k次游戏,然后是n个字符串.每局開始.字符串为空串,然后两人轮流在末尾追 ...

  2. codeforces 325B Stadium and Games

    这道题思路很简单,设刚开始队伍数为d=2^p*x,其中x是奇数,则比赛场次n=(2^p-1)*x+(x-1)*x/2,然后从0开始枚举p的值,接着解一元二次方程x^2+(2^(p+1)-3)x-2*n ...

  3. Codeforces 980 E&period; The Number Games

    \(>Codeforces \space 980 E. The Number Games<\) 题目大意 : 有一棵点数为 \(n\) 的数,第 \(i\) 个点的点权是 \(2^i\) ...

  4. CodeForces 455B&Tab;A Lot of Games (博弈论)

    A Lot of Games 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/J Description Andrew, Fedo ...

  5. Codeforces 455B A Lot of Games

    http://codeforces.com/contest/455/problem/B 题目大意: 给出n个字符串,进行k次游戏,每次游戏输家下次作为先手,游戏规则为每次放一个字母,导致当前构造的字符 ...

  6. Codeforces 455B A Lot of Games:博弈dp【多局游戏】

    题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...

  7. codeforces 455B A Lot of Games(博弈,字典树)

    题目 参考自博客:http://blog.csdn.net/keshuai19940722/article/details/38455269 //字典树,博弈 根据当前节点的后续来确定当前节点的状态, ...

  8. CodeForces 456D&amp&semi;455B--A Lot of Games(Trie&plus;博弈)

    题意:给n个字符串.进行k次游戏.每局开始,字符串为空串,然后两人轮流在末尾追加字符,保证新的字符串为集合中某字符串的前缀,不能操作者输,新一轮由上一句输的人先手. 题解: #看到此题毫无头绪,队友写 ...

  9. Codeforces 455B A Lot of Games 字典树上博弈

    题目链接:点击打开链接 题意: 给定n个字符串,k局游戏 对于每局游戏,2个玩家轮流给一个空串加入一个小写字母使得加完后的字符串不是n个字符串的前缀. 输家下一轮先手 问是先手必胜还是后手必胜 思路: ...

随机推荐

  1. TextView属性android&colon;ellipsize&equals;&quot&semi;marquee&quot&semi;不生效的解决办法

    最近自己在写自己的第一个app,过程中遇到了这个问题,查了不少帖子,经过尝试发现,这种问题一般分为两类: 1. TextView的Text值赋值后不更改,很多帖子上说如下写法就可以生效: <Te ...

  2. Android 生成和Pull解析xml

    一.单个对象生成xml 生成以下xml,该怎么生成呢? <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <accou ...

  3. 《Java程序员修炼之道》

    原子类:java.util.concurrent.atomic 线程锁:java.util.concurrent.locks 对付死锁:boolean acquired = lock.tryLock( ...

  4. cocos2d-x游戏开发 跑酷&lpar;两&rpar; 物理世界

    原创.转载请注明出处:http://blog.csdn.net/dawn_moon/article/details/21240343 泰然的跑酷用的chipmunk物理引擎.我没有细致学过这个东西. ...

  5. Android使用应用程序资源(、颜色数组、尺寸、弦、布尔、整型)

    一.Android资源分类详细解释   1.Android资源类别 Android中的资源分为两大类 : 可直接訪问的资源, 无法直接訪问的原生资源; -- 直接訪问资源 : 这些资源能够使用 R. ...

  6. &period;NET 基础 一步步 一幕幕&lbrack;面向对象之堆、栈、引用类型、值类型&rsqb;

    堆.栈.引用类型.值类型 内存分为堆和栈(PS:还有一种是静态存储区域 [内存分为这三种]),值类型的数据存储在栈中,引用类型的数据存储在堆中. 堆.栈: 堆和栈的区别: 栈是编译期间就分配好的内存空 ...

  7. Vue练手项目(包含typescript版本)

    本项目的git仓库https://github.com/lznism/xiachufang-vue 对应的使用typescript实现的版本地址https://github.com/lznism/xi ...

  8. Random Forest vs GradientBoostingDecisionTree

    相同 随机森林和GBDT都属于集成算法,base model都是决策树. 不同 随机森林 随机森林是决策树的bagging. bagging通过重复对原训练数据集上进行有放回地采样生成的数据集用bas ...

  9. iOS 枚举 初体验

    iOS枚举 我的code /*文件名 SC_CDV_OCR.m*/ typedef enum _OCRResultState { OCRResultStateOK = 1, OCRResultStat ...

  10. echarts-map-区县

    首先通过百度获取经纬度 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&q ...