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. .PHP生成静态html文件的方法

    1. [代码][PHP]代码     1,下面使用模版的一个方法!   <?php $fp = fopen ("templets.html","a");  ...

  2. Yii的缓存机制之数据缓存

    具体说法就是可以缓存变量信息. 设置:Yii::app()->cache->set(名字, 值, 过期时间): 使用:Yii::app()->cache->get(名字); 删 ...

  3. AC自动机-题目集合

    AC自动机-题目集合 模板 如果你想要学习AC自动机,推荐一些学习资料. 学习可以看这篇博客 http://blog.csdn.net/niushuai666/article/details/7002 ...

  4. 看 迪杰斯特拉(Dijsktra)算法体会

    迪杰斯特拉 看啊哈算法中迪杰斯特拉算法体会: 算法思路 : 1.先找到源头到其他点的最短路: 2.以最短路作为中转点进行比较,用一个dis数组保存源头到他的最优距离 3.用循环进行最优筛选: #inc ...

  5. 51nod-1065:最小正子段和(STL)

    N个整数组成的序列a11,a22,a33,…,ann,从中选出一个子序列(aii,ai+1i+1,…ajj),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的. 例如:4,-1 ...

  6. 「LOJ#10034」「一本通 2.1 例 2」图书管理 (map

    题目描述 图书管理是一件十分繁杂的工作,在一个图书馆中每天都会有许多新书加入.为了更方便的管理图书(以便于帮助想要借书的客人快速查找他们是否有他们所需要的书),我们需要设计一个图书查找系统. 该系统需 ...

  7. angular之两种路由

    安装angular npm install -g @angular/cli ng new myapp ng g component componentName 自带路由 引入:angular-rout ...

  8. Boost-ioservices介绍

    IO模型 io_service对象是asio框架中的调度器,所有异步io事件都是通过它来分发处理的(io对象的构造函数中都需要传入一个io_service对象). asio::io_service i ...

  9. 杂项:SVN 常用方法

    ylbtech-杂项:SVN 1.返回顶部 1. bin obj *.suo*.user *.csproj.user *.o *.lo *.la *.al .libs *.so *.so.[0-9]* ...

  10. Array 对象

    Array的对象用于在单个的变量中存储多个值. constructor 返回对创建此对象的数组函数的引用. demo: let arr=[];  arr.constructor==Array let ...