http://codeforces.com/gym/100283/problem/F

思路是二分第几行,二分出来的行是总和 >= n的,那么第k - 1行一定要选,那么再在第k行中二分那一列、

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
LL f1(LL n) {
return n * (n + ) / * ( * n + ) / ;
}
LL f2(int which, int pos) {
if (pos <= which) {
return 1LL * pos * ( + pos) / ;
} else {
LL t = * which - - pos;
return 1LL * which * ( + which) - which - f2(which, t);
}
}
void work() {
LL n;
scanf("%I64d", &n);
int be = , en = 2e6 + ;
while (be <= en) {
int mid = (be + en) >> ;
LL res = f1(mid);
if (res >= n) {
en = mid - ;
} else be = mid + ;
}
// cout << be << endl;
// cout << f1(be) << endl;
LL ans = ((LL)be - ) * (be - );
// cout << n << endl;
// cout << f1(be - 1) << endl;
n -= f1(be - );
// cout << n << endl;
// cout << f2(4, 8) << endl;
int L = , R = * be - ;
while (L <= R) {
int mid = (L + R) >> ;
LL res = f2(be, mid);
if (res >= n) {
R = mid - ;
} else L = mid + ;
}
ans += L;
static int f = ;
printf("Case %d: %I64d\n", ++f, ans);
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
// freopen("army.in", "r", stdin);
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

F. Bakkar In The Army 二分的更多相关文章

  1. Gym - 100283F F. Bakkar In The Army —— 二分

    题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...

  2. Gym - 100283F Bakkar In The Army(二分)

    https://vjudge.net/problem/Gym-100283F 题意: 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 .... 给出这样的序列,然后给出一个n,计算从1 ...

  3. Gym 100283F Bakkar In The Army

    数学公式: n^2的前n项和n(n+1)(2*n+1)/6,用二分进行查找: 算出层数后继续二分查找位于这一层的哪一位,也可以推出相应公式 #include <iostream> #inc ...

  4. 【CodeForces】961 F. k-substrings 字符串哈希+二分

    [题目]F. k-substrings [题意]给定长度为n的串S,对于S的每个k-子串$s_ks_{k+1}...s_{n-k+1},k\in[1,\left \lceil \frac{n}{2} ...

  5. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  6. POJ 1759 Garland(二分+数学递归+坑精度)

    POJ 1759 Garland  这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...

  7. hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. HDU 1969 Pie [二分]

    1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...

  9. 二维动态规划&&二分查找的动态规划&&最长递增子序列&&最长连续递增子序列

    题目描述与背景介绍 背景题目: [674. 最长连续递增序列]https://leetcode-cn.com/problems/longest-continuous-increasing-subseq ...

随机推荐

  1. zabbix 中 宏 的介绍

    宏的作用是便于在模板.items.trigger中的引用.宏的名称为 {$名称},宏的字符范围为 A~Z.0~9._ . 例如: 在key中的宏: net.tcp.service[ssh,{$SSH_ ...

  2. C++中指针和指针变量

    指针和指针变量的理解: #include<iostream> using namespace std; int main() { int n; int * m; m = &n; n ...

  3. git bash使用端口转发连接服务器

    之前的配置是 url = user@xx.xx.xx.xx:/home/tutu/thelib/ww.git xx.xx.xx.xx是服务器的外网地址,其内网地址是zz.zz.zz.zz 但是现在服务 ...

  4. SDOI2017 Round1 Day2 题解

    T2好厉害啊……AK不了啦……不过要是SCOI考这套题就好了240保底. BZOJ4819 新生舞会 模板题,分数规划+二分图最大权匹配. 费用流跑得过,可以不用KM. UPD:分数规划用迭代跑得飞快 ...

  5. myeclipse_JUnit导包问题

    第一种方式: MyEclipse创建JUnit单元测试时,在需要测试的代码段前键入“@Test”时,按ctrl和1一般会自动提示JUnit需要导包,但有时会无法提示这个建议,如图所示.该经验教你如何解 ...

  6. hibernate学习三 精解Hibernate之核心文件

    一 hibernate.cfg.xml详解 1 JDBC连接: 2 配置C3P0连接池: 3 配置JNDI数据源: 4 可选的配置属性: 5 hibernate二级缓存属性 6 hibernate事务 ...

  7. 使用 Git 命令去管理项目的版本控制(一)

    参考资料:参考  参考 声明本文是作者原创,是自己的学习笔记,仅供学习参考. 在 10.11.2Mac系统中,要显示隐藏的文件夹使用命令行: defaults write com.apple.find ...

  8. 3-6局部变量的存储方式 & 3-7字符型字面值

    基础数据类型变量的存储 重点介绍方法级的变量,局势局部变量 存储中怎么存储呢? int n=100; 在栈中开辟内存存储空间. n是内存空间的别名 3-7字符型字面值 单引号不能丢,必须是英文状态. ...

  9. 在CentOS6.6上以replSet方式部署MongoDB集群

    此文已由作者袁欢授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 部署方式在3台centos6.6系统上以Replica Set方式部署mongodb3.0.2集群. 官方参考 ...

  10. Unity NGUI学习

    环境 Unity4.3    NGUI v3.68 导入 Project界面->右键->import package->custom package载入安装包即可 untiy4.6用 ...