【AtCoder - 4242 】To Infinity(思维)

题干:

Problem Statement

Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:

  • Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 3334becomes 44445 becomes 555556 becomes 6666667 becomes 77777778 becomes 88888888 and 9 becomes 9999999991 remains as 1.

For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next. You are interested in what the string looks like after 5×1015 days. What is the K-th character from the left in the string after 5×1015 days?

Constraints

  • S is a string of length between 1 and 100 (inclusive).
  • K is an integer between 1 and 1018 (inclusive).
  • The length of the string after 5×1015 days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity's string after 5×1015days.

Sample Input 1

1214
4

Sample Output 1

2

The string S changes as follows:

  • Now: 1214
  • After one day: 12214444
  • After two days: 1222214444444444444444
  • After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444

The first five characters in the string after 5×1015 days is 12222. As K=4, we should print the fourth character, 2.

Sample Input 2

3
157

Sample Output 2

3

The initial string is 3. The string after 5×1015 days consists only of 3.

Sample Input 3

299792458
9460730472580800

Sample Output 3

2

题目大意:

给定初始的一串数字,之后每一天每个数字会复制该数字次,比如’12223’,下一天变为’1222222333’,如此类推,
问经过5e15天后第k位数字是多少。

解题报告:

   因为是个给定的数字啊!!5e15这个数字谁都承受不了啊!!读入的字符串的大小小于100位数。所以显然我们只需要找前缀1的个数就可以了。如果查询的k大于前缀1的个数,那么就输出1后面的第一个数就是了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 500 + 5;
ll k,cnt;
int main()
{string s;cin>>s;int len = s.length();for(int i = 0; i<len; i++) {if(s[i] != '1') break;cnt++;}cin>>k;if(k <= cnt) printf("1\n");else printf("%c\n",s[cnt]);return 0 ;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441360.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java面向对象编程集合边框_JAVA 面向对象 集合框架

1.Java集合框架提供了一套性能优良、使用方便的接口和类&#xff0c;它们位于java.util包中如果并不知道程序运行时会需要多少对象&#xff0c;或者需要 更复杂方式存储对象——可以使用Java集合框架2.java集合框架包括接口、具体类、算法接口&#xff1a;Collection&#xff1…

【HDU - 2072 】单词数(字符串读入技巧,sstream大法,水题,字符串读入格式)

题干&#xff1a; lily的好朋友xiaoou333最近很空&#xff0c;他想了一件没有什么意义的事情&#xff0c;就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。 Input 有多组数据&#xff0c;每组一行&#xff0c;每组就是一篇小文章。每篇小文章都…

java生成world文件_HelloWorld.java文件如何创建?

原创HelloWorld.java文件如何创建&#xff1f;编辑:小丸子 来源:PC下载网时间:2017-10-17 19:55:54相信各位刚接触JAVA的新人都希望尽快编写出自己的第一个程序,今天PC下载网小编和你一起学习HelloWorld程序1.首先我们先点击“开始”—然后是“所有程序”—在然后是“附件”—记…

【HDU - 1251 】统计难题(字典树,求拥有公共前缀的字符串数量)

题干&#xff1a; Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input 输入数据的第一部分是一张单词表,每行一个单词,单词的长度不超过10,它们代表的是…

java 轮询请求接口_js调用轮询接口

##### 项目中遇到需要很多个需要轮询处理的接口&#xff0c;然后简单的封装了下&#xff0c;做个记录&#xff0c;以后用到类似的直接copy #####// polling-utils.js/*** descripting 轮询功能* param {String} type 请求类型* param {String} url 地址* param {Object} data 请…

【POJ - 2001 】Shortest Prefixes (字典树,查询重复前缀区间)

题干&#xff1a; A prefix of a string is a substring starting at the beginning of the given string. The prefixes of "carbon" are: "c", "ca", "car", "carb", "carbo", and "carbon". Note t…

mysql use index用法_MySQL中USE INDEX 和 FORCE INDEX

问题在一次生产环境排查性能问题时, 发现有个请求在一些用户的数据量比较大的情况下, 最高耗时差不多要3s. 而且还是一个轮询的请求.原因在排查问题时, 定位到是执行某条SQL时在用户的数据比较大的情况下, SQL执行耗时要1.5s.mysql> SELECT count(1)-> FROM-> cc_sess…

【AtCoder - 4244 】AtCoder Express 2 (区间dp 或 暴力枚举,思维)

题干&#xff1a; In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east. A company called AtCoder Express possesses Mtrains, and the train i runs from City Li to City Ri (it is possible that L…

【HDU - 3068】最长回文(Manacher算法,马拉车算法求最长回文子串)

题干&#xff1a; 给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input 输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c...y,z组成的字符串S 两组case之间由空行隔开(该空行不用…

java程序员面试需要英语吗_Java程序员和高级程序员面试30题(英语)

Java程序员和高级程序员面试30题(英语)* Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?A. The class System has a variable out that represents the standard output, and the variable err that represe…

【HDU - 1867 】A + B for you again(KMP,next数组应用)

题干&#xff1a; Generally speaking, there are a lot of problems about strings processing. Now you encounter another such problem. If you get two strings, such as “asdf” and “sdfg”, the result of the addition between them is “asdfg”, for “sdf” is …

wifisetting.java_Wifi 笔记 | 启动流程

csd&#xff1a;csdn_of_coder/article/details/51541094aosp: Android OAndroid网络各个模式中&#xff0c;Wifi应该是目前最常用的一种网络方式了&#xff1b;下面就简单介绍下Android中Wifi的启动流程。当我在Setting菜单里点击打开Wifi时&#xff0c;调用的入口函数是WifiM…

【CodeForces - 589F】Gourmet and Banquet (贪心,思维,二分)

题干&#xff1a; A gourmet came into the banquet hall, where the cooks suggested n dishes for guests. The gourmet knows the schedule: when each of the dishes will be served. For i-th of the dishes he knows two integer moments in time ai and bi (in second…

java 调用动态链接库_JAVA技巧:JNative调用动态链接库问题(SOS)

动态链接库的方法如下&#xff1a;__declspec(dllexport) ret __stdcall rLachTran(const char *pc_trancode,const char *pc_clicode,const char *pc_orgcode,const char *pc_ttycode,const int i_brandid,const char *pc_reqstamp,const int i_reqseqno,const char *pc_svrip…

SPFA算法模板

简单的一个模板吧&#xff0c;留个底。如果要判负环的话&#xff0c;需要加一个cnt数组记录入队次数就可以了。 void spfa(int st) {memset(dis,INF,sizeof dis);queue<int> q;q.push(st);dis[st]0;vis[st]1;while(!q.empty()) {int cur q.front();q.pop();vis[cur]0;i…

js和php能生成一样的随机数_JavaScript_JS生成某个范围的随机数【四种情况详解】,前言: JS没有现成的函数,能 - phpStudy...

JS生成某个范围的随机数【四种情况详解】前言&#xff1a;JS没有现成的函数&#xff0c;能够直接生成指定范围的随机数。但是它有个函数&#xff1a;Math.random() 这个函数可以生成 [0,1) 的一个随机数。利用它&#xff0c;我们就可以生成指定范围内的随机数。而涉及范围的话…

【POJ - 3347 】Kadj Squares (计算几何,思维 或 扫描线)

题干&#xff1a; In this problem, you are given a sequence S1, S2, ..., Sn of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive x-y quarter of the plane, such that their sides make 45 degrees w…

按钮开关java代码,Android自定义实现开关按钮代码

我们在应用中经常看到一些选择开关状态的配置文件&#xff0c;做项目的时候用的是android的Switch控件&#xff0c;但是感觉好丑的样子子个人认为还是自定义的比较好&#xff0c;先上个效果图&#xff1a;实现过程&#xff1a;1.准备开关不同状态的两张图片放入drawable中。2.x…

java创建的zip没写入权限,java中的zip创建错误

我正在使用ZipOutputStream,FileOutputStream和FileInputStream.首先我创建了一个包含一个文件的文件夹它成功创建了.然后我尝试创建zip文件.动态地,它首次正确创建文件,但第二次,第三次在打开文件时出错.Error: zip [path/././file.zip] Cannot open The process cannot acces…

【qduoj - 夏季学期创新题】最长公共子串(水题暴力枚举,不是LCS啊)

题干&#xff1a; 描述 编写一个程序&#xff0c;求两个字符串的最长公共子串。输出两个字符串的长度&#xff0c;输出他们的最长公共子串及子串长度。如果有多个最长公共子串请输出在第一个字符串中先出现的那一个。 特别注意公共子串中可能包含有空格&#xff0c;但不计回车…