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. 花了5天时间,终于解决了一个bug,心情非常愉快,憋了这么久,不吐不快

    http://www.cnweblog.com/fly2700/archive/2011/12/06/318916.html (转载) 花了5天时间,终于解决了一个bug,心情非常愉快,憋了这么久,不 ...

  2. Android图片加载神器之Fresco, 基于各种使用场景的讲解

    Fresco是Facebook开源Android平台上一个强大的图片加载库,也是迄今为止Android平台上最强大的图片加载库. 优点:相对于其他开源的第三方图片加载库,Fresco拥有更好的内存管理 ...

  3. hdu-5000 Clone(dp)

    题目链接: Clone Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Pro ...

  4. Mysql数据库--语句整理/提升/进阶/高级使用技巧

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  5. JavaScript-Tool:validate.js-un

    ylbtech-JavaScript-Tool:validate.js 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. http://validatejs. ...

  6. MTCNN人脸检测识别笔记

    论文:Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks 论文链接:https:// ...

  7. Bishops

    题意: 给定一个 $n*n$ 的国际棋盘,求问在上面放 $K$ 个象的方案数. 解法: 首先可以发现黑格和白格互不干扰,这样我们可以将黑格,白格分别求出. 考虑 $f(i,j)$ 表示坐标化后考虑长度 ...

  8. Easyui TextBox 添加事件的方法

    $("#txtPaySideId").textbox('textbox').bind("click", function () { showPlatform() ...

  9. NDK环境搭建(Native Code的编译,不需要Cygwin)

    分类: android2013-06-21 15:49 475人阅读 评论(0) 收藏 举报 Android NDK 目录(?)[-] System and Software Requirements ...

  10. Codevs 1569 最佳绿草

    1569 最佳绿草  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 贝茜正计划着这一天如何美美地咀嚼春天的绿 ...