日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【AtCoder - 4242 】To Infinity(思维)

發(fā)布時(shí)間:2023/12/10 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【AtCoder - 4242 】To Infinity(思维) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題干:

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?333,?4becomes?4444,?5?becomes?55555,?6?becomes?666666,?7?becomes?7777777,?8?becomes?88888888?and?9?becomes?999999999.?1?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

題目大意:

給定初始的一串?dāng)?shù)字,之后每一天每個(gè)數(shù)字會(huì)復(fù)制該數(shù)字次,比如’12223’,下一天變?yōu)椤?222222333’,如此類推,
問經(jīng)過5e15天后第k位數(shù)字是多少。

解題報(bào)告:

? ?因?yàn)槭莻€(gè)給定的數(shù)字啊!!5e15這個(gè)數(shù)字誰都承受不了啊!!讀入的字符串的大小小于100位數(shù)。所以顯然我們只需要找前綴1的個(gè)數(shù)就可以了。如果查詢的k大于前綴1的個(gè)數(shù),那么就輸出1后面的第一個(gè)數(shù)就是了。

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 ;}

?

總結(jié)

以上是生活随笔為你收集整理的【AtCoder - 4242 】To Infinity(思维)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。