Codeforces 1216E2 枚举位数+二分
两个二分 枚举位数
#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 枚举位数+二分的更多相关文章
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- Codeforces 807C - Success Rate(二分枚举)
题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...
- Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))
题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...
- Codeforces 912 E.Prime Gift (折半枚举、二分)
题目链接:Prime Gift 题意: 给出了n(1<=n<=16)个互不相同的质数pi(2<=pi<=100),现在要求第k大个约数全在所给质数集的数.(保证这个数不超过1e ...
- Codeforces 912E Prime Gift ( 二分 && 折半枚举 && 双指针技巧)
题意 : 给你 N ( 1 ≤ N ≤ 16 ) 个质数,然后问你由这些质数作为因子的数 ( 此数不超 10^18 ) & ( 不一定需要其因子包含所给的所有质数 ) 的第 k 个是什么 分析 ...
- Codeforces 888E:Maximum Subsequence(枚举,二分)
You are given an array a consisting of n integers, and additionally an integer m. You have to choose ...
- Codeforces 660C - Hard Process - [二分+DP]
题目链接:http://codeforces.com/problemset/problem/660/C 题意: 给你一个长度为 $n$ 的 $01$ 串 $a$,记 $f(a)$ 表示其中最长的一段连 ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- Codeforces - 773A - Success Rate - 二分 - 简单数论
https://codeforces.com/problemset/problem/773/A 一开始二分枚举d,使得(x+d)/(y+d)>=p/q&&x/(y+d)<= ...
随机推荐
- 合并多个tensorflow模型的办法
直接上代码: import tensorflow as tf from tensorflow.python.tools import freeze_graph from tensorflow.pyth ...
- Java.lang 包 util 包等各个包详解
java.lang 该包提供了 Java 编程的基础类,例如 Object.Math.String.StringBuffer.System.Thread 等,不使用该包就很难编写 Java 代码了. ...
- Android netty客户端入门
新建项目,加入netty库 implementation 'io.netty:netty-all:4.1.36.Final'
- idea的eclipse快速定位link with editor
eclipse的link with editor,个人感觉非常有用的一个功能 idea也有这个功能autoscroll from source
- 《C++ Primer》读书笔记之第15章:面向对象编程
一.面向对象概述 1. 面向对象的三个基本特性 封装.继承和多态. 2. 封装 指把隐藏对象的实现细节,仅对外提供接口,从而达到接口与实现分离的效果.封装的好处:一是提高数据的安全性,用户只能使用对象 ...
- DB2 数据库权限
以下内容转载: http://blog.csdn.net/xiyuan1999/article/details/8135263 DB2中的权限 DB2 中有三种主要的安全机制,可以帮助 DBA 实现 ...
- 创建web服务器
用node创建本地web服务 1,创建本地文件server.js var http = require('http'); var url=require('url'); var fs=require( ...
- 什么是Sprint?
Sprint指Scrum团队完成一定数量工作所需的短暂.固定的周期.Sprint是Scrum和敏捷的核心,找到正确的Sprint周期将帮助您的敏捷团队交付更高质量的产品. “在Scrum框架中,庞大且 ...
- php 获取城市ip
/** * 获取ip城市信息 * CreateBy XueSong * @param string $ip * @return array|bool|mixed */ function getCity ...
- KeyValuePair<string, string>
; #region CUP Method /// <summary> /// 请求与响应的超时时间 /// </summary> static public int Timeo ...