两个二分 枚举位数

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll ten[];
ll check1(ll x) {
ll ans = ;
ll l, r;
for (ll i = ; i <= ; i++) {
l = ten[i], r = ten[i + ] - ;
if (r < x) {
ans += i * ( * x - l - r) * (r - l + ) / ;
} else {
ans += i * (x - l) * (x - l + ) / ;
break;
}
}
return ans;
}
ll check2(ll x) {
ll ans = ;
ll l, r;
for (ll i = ; i <= ; i++) {
l = ten[i], r = ten[i + ] - ;
if (r <= x) {
ans += i * (r - l + );
} else {
ans += i * (x - l + );
break;
}
}
return ans;
}
int main () {
ten[] = ;
for (int i = ; i <= ; i++) {
ten[i] = ten[i - ] * 10LL;
}
int Q;
scanf("%d", &Q);
while (Q--) {
ll n;
scanf("%lld", &n);
ll l = , r = 1e9, mid;
while (l < r - ) {
mid = (l + r) >> ;
if (check1(mid) < n) {
l = mid;
} else {
r = mid;
}
}
n -= check1(r - );
if (n == ) {
printf("%d\n", (r - ) % );
continue;
}
l = ;
r = 1e9;
while (l < r - ) {
mid = (l + r) >> ;
if (check2(mid) < n) {
l = mid;
} else {
r = mid;
}
}
n -= check2(r - );
int len = ;
ll xxx = r, xxxx = r;
while (xxx > ) {
xxx /= 10LL;
len++;
}
len -= n;
if (len < ) {
continue;
}
while (len--) {
xxxx /= ;
}
printf("%lld\n", xxxx % );
}
}

Codeforces 1216E2 枚举位数+二分的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. Codeforces 807C - Success Rate(二分枚举)

    题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...

  3. Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))

    题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...

  4. Codeforces 912 E.Prime Gift (折半枚举、二分)

    题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...

  5. Codeforces 912E Prime Gift ( 二分 && 折半枚举 && 双指针技巧)

    题意 : 给你 N ( 1 ≤ N ≤ 16 ) 个质数,然后问你由这些质数作为因子的数 ( 此数不超 10^18 ) & ( 不一定需要其因子包含所给的所有质数 ) 的第 k 个是什么 分析 ...

  6. Codeforces 888E:Maximum Subsequence(枚举,二分)

    You are given an array a consisting of n integers, and additionally an integer m. You have to choose ...

  7. Codeforces 660C - Hard Process - [二分+DP]

    题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...

  8. Educational Codeforces Round 61 D 二分 + 线段树

    https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...

  9. Codeforces - 773A - Success Rate - 二分 - 简单数论

    https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...

随机推荐

  1. 欢迎访问我的csdn博客

    csdn博客:https://blog.csdn.net/qq_27307175 这个里面有:许许多多的专业文章. 本人主要研究:网络工程,VMware虚拟化,docker容器,以及Linux等技术, ...

  2. Python学习笔记——esle和with 语句

    1. else与while组合 def showMaxFactor(num): count = num // 2 while count > 1: if num % count == 0: pr ...

  3. MySQL索引解析(联合索引/最左前缀/覆盖索引/索引下推)

    本节内容: 1)索引基础 2)索引类型(Hash索引.有序数组.B+树) 3)索引的几个常见问题 1)联合索引 2)最左前缀原则 3)覆盖索引 4)索引下推 1. 索引基础 索引对查询的速度有着至关重 ...

  4. shell 监控

    #!/bin/shsource /etc/profileserverName=$1dingDingName=$2 #获取内存情况memory=(`free | awk 'NR==2{print $2, ...

  5. axios对请求各种异常情况处理的封装

    前端网络请求封装 前端采用了axios来处理网络请求,为了避免在每次请求时都去判断各种各样的网络情况,比如连接超时.服务器内部错误.权限不足等等不一而足,我对axios进行了简单的封装,这里主要使用了 ...

  6. 【AtCoder】ARC079

    ARC079题解 C - Cat Snuke and a Voyage #include <bits/stdc++.h> #define fi first #define se secon ...

  7. Java web server 基本实现原理

    public class WebServer { //服务端Socket只要一个,所以定义成static, 同一时间只能一个线程访问(主线程) private static ServerSocket ...

  8. Eureka【支持Remote Region】

    工程公共pom依赖 <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncod ...

  9. python 自动化测试

    安装selenium 安装命令: pip install selenium 测试 打开一款Python编辑器,默认Python自带的IDLE也行.创建 baidu.py文件,输入以下内容: from ...

  10. Python中的幽灵—编码方式

    首先要搞懂本地操作系统编码与系统编码的区别: 本地操作系统编码方式与操作系统有关,Linux默认编码方式为utf-8,Windows默认编码方式为gbk: 系统编码方式与编译器or解释器有关,Pyth ...