codeforces 1177B
题目链接:http://codeforces.com/problemset/problem/1177/B
B. Digits Sequence (Hard Edition)
Let's write all the positive integer numbers one after another from 11 without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to print the kk-th digit of this sequence.
Input
The first and only line contains integer kk (1≤k≤10121≤k≤1012) — the position to process (11-based index).
Output
Print the kk-th digit of the resulting infinite sequence.
Examples
input
7
output
7
input
21
output
5
题意概括:把正整数按顺序排成一个字符串,求第n个字符是什么
解题思路:一位正整数有9个,两位有90个,三位900个,先求出这个数是几位的,然后求出是第几个,最后求出是这个数的第几位
#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))
#define MIN(a,b,c) (a<b?(a<c?a:c):(b<c?b:c))
using namespace std;typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 100;
const int MAXN = 2750131;
ll T,n,m,i,j;
ll gcd(ll p,ll q)
{return q==0?p:gcd(q,p%q);}ll g[200005];int main()
{ios::sync_with_stdio(false);ll a[20];ll k=1,s=1,sum=9;for(i=0;s<1e12;i++){a[i]=s*sum*k;s*=10;k++;// cout<<a[i]<<endl;}cin>>n;if(n<10){cout<<n<<endl;return 0;}sum=0;i=0;k=1;s=1;ll m=n;while(m>a[i]){m-=a[i];i++;k++;s=pow(10,i);sum=s-1;}
// cout<<m<<endl;ll ans=(m)/k+sum;if(m%k){ans++;}
// cout<<ans<<endl;ll sk=m%k;if(sk==0){sk=k;}//cout<<sk<<" "<<k<<endl;while(ans>0){// cout<<ans<<" "<<k<<" "<<sk<<endl;if(sk==k){cout<<ans%10<<endl;break;}else{ans/=10;k--;}} return 0;
}
codeforces 1177B相关推荐
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- CodeForces 获得数据
针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...
- codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...
题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...
- CodeForces 595A
题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...
- codeforces A. Jeff and Digits 解题报告
题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)
Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...
最新文章
- 从车联网到工业智联网
- 谈谈大家对PHP框架的各种误解
- Spring实现web开发的环境搭建
- NOIP模拟测试39,思维禁锢专场「工业题·玄学题·卡常题」
- 用于检测敏感词的 PHP 扩展
- c++ for each 遍历tuple
- Redis 实用技术——事务
- 4.2 算法之数论 185 反正切函数的应用 scratch
- 日文简历 模板
- 21天打卡活动 leetcode 301
- Threejs实现3d地球记录(5)
- 冰羚-README.md翻译
- 夜神安卓模拟器怎么设置代理
- 相亲小程序如何做到年入百万?盈利模式是什么?
- ES6的Lambda表达式
- writeline是什么意思_write是什么意思_write的翻译_音标_读音_用法_例句_爱词霸在线词典...
- java计算机毕业设计宠物店管理系统设计与实现(附源码、数据库)
- 副驾驶的意义_副驾驶对女人的意义是什么样的?
- 云计算虚拟化技术总结
- 音频插件包:Unfiltered Audio Plugins Bundle for Mac