F. Bakkar In The Army 二分
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 二分的更多相关文章
- 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 ...
- 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 ...
- Gym 100283F Bakkar In The Army
数学公式: n^2的前n项和n(n+1)(2*n+1)/6,用二分进行查找: 算出层数后继续二分查找位于这一层的哪一位,也可以推出相应公式 #include <iostream> #inc ...
- 【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} ...
- 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 ...
- POJ 1759 Garland(二分+数学递归+坑精度)
POJ 1759 Garland 这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...
- hdu 2444 The Accomodation of Students(二分匹配 匈牙利算法 邻接表实现)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- HDU 1969 Pie [二分]
1.题意:一项分圆饼的任务,一堆圆饼共有N个,半径不同,厚度一样,要分给F+1个人.要求每个人分的一样多,圆饼允许切但是不允许拼接,也就是每个人拿到的最多是一个完整饼,或者一个被切掉一部分的饼,要求你 ...
- 二维动态规划&&二分查找的动态规划&&最长递增子序列&&最长连续递增子序列
题目描述与背景介绍 背景题目: [674. 最长连续递增序列]https://leetcode-cn.com/problems/longest-continuous-increasing-subseq ...
随机推荐
- 【概念】SVG(2)
Style <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg&qu ...
- 大数相乘(hdu 1402)
------------------题目链接--------------------- 题目没啥说的,两个数相乘,fft,一发模板就AC,kuangbin模板大法好,不懂原理的小白也能体验AC. 个人 ...
- Linux-用户和权限
1 Linux所有内容都是文件 归一的思想 面向对象的思想 文件只需要做增删改查的操作 2 延迟读取 一般的文本读取工具都是先将内容全部都读入内存中 cat的机制不同 是读一行显示一行 这与它的功能有 ...
- albus就是要第一个出场(线性基)
传送门 这个题题目描述真怪异--就不能说人话吗-- 人话:给定长为n的序列A,定义f(s)为集合s内所有元素异或值,求A的所有子集的f值从小到大排列后,q在其中第一次出现的下标对10086取模的值. ...
- MongoDB监控之一:运行状态、性能监控,分析
为什么要监控? 监控及时获得应用的运行状态信息,在问题出现时及时发现. 监控什么? CPU.内存.磁盘I/O.应用程序(MongoDB).进程监控(ps -aux).错误日志监控 1.4.1 Mong ...
- RTC驱动程序分析
drivers\rtc\rtc-s3c.c s3c_rtc_init platform_driver_register s3c_rtc_probe ...
- CS231n 2016 通关 第四章-反向传播与神经网络(第一部分)
在上次的分享中,介绍了模型建立与使用梯度下降法优化参数.梯度校验,以及一些超参数的经验. 本节课的主要内容: 1==链式法则 2==深度学习框架中链式法则 3==全连接神经网络 =========== ...
- 机器学习之SVM支持向量机
前言 以下内容是个人学习之后的感悟,转载请注明出处~ 简介 支持向量机(support vector machine),简称SVM,通俗来讲,它是一种二类分类模型,其基本模型定义 ...
- Apple Tree
题意: 给一有根树,每个叶子上有一些苹果,现在要求你拿掉一些苹果,使得每一个点的 儿子的子树内的苹果数相同. 解法: 首先可以发现$cnt$个叶子节点之间的关系可以用$cnt-1$个独立方程表示出来. ...
- g2o扩展,然后重新编译生成新库。
orb作者有g2o扩展,g2o原作者也有g2o扩展,等各项基本功扎实以后,考虑把他们整合在一起,再加上高博扩展的g2o,统一cmake,make,然后能make install 正常使用,就最好了.