Remove a Progression

問(wèn)題描述:

You have a list of numbers from 1 to n written from left to right on the blackboard.

You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering only remaining numbers). You wipe the whole number (not one digit).

When there are less than i numbers remaining, you stop your algorithm.

Now you wonder: what is the value of the x-th remaining number after the algorithm is stopped?

(翻譯:黑板上有從左到右從1到n的數(shù)字列表。

執(zhí)行一個(gè)由多個(gè)步驟組成的算法(步驟為1索引)。在第i步中,刪除第i個(gè)數(shù)字(只考慮剩余的數(shù)字)。你擦掉整個(gè)數(shù)字(不是一個(gè)數(shù)字)。

當(dāng)剩下的數(shù)字少于i時(shí),停止您的算法。

現(xiàn)在你想知道:算法停止后,第x個(gè)剩余數(shù)字的值是多少?


Problem - A - Codeforces

輸入內(nèi)容:

The first line contains one integer T (1≤T≤100) — the number of queries. The next T lines contain queries — one per line. All queries are independent.(第一行包含一個(gè)整數(shù)t(1≤t≤100)-查詢(xún)數(shù)。接下來(lái)的T行包含查詢(xún)-每行一個(gè)。所有查詢(xún)都是獨(dú)立的。)

Each line contains two space-separated integers n and x (1≤x<n≤109) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least x numbers.(每行包含兩個(gè)空格分隔的整數(shù)n和x(1≤x<n≤109)-列表的長(zhǎng)度和我們想知道的位置。它保證在算法結(jié)束后,列表仍然包含至少x個(gè)數(shù)字。)

輸出內(nèi)容:

Print T integers (one per query) — the values of the x-th number after performing the algorithm for the corresponding queries.(打印T整數(shù)(每個(gè)查詢(xún)一個(gè))-執(zhí)行相應(yīng)查詢(xún)的算法后的第x個(gè)數(shù)字的值。)

樣例:

3

3? 1

4? 2

12? 6

過(guò)程:

1:第一個(gè)結(jié)果:

當(dāng)n=3,x=1時(shí):

原始數(shù)字:1、2、3

第一步,去掉第一個(gè)數(shù)字:2、3

第二步,去掉第二個(gè)數(shù)字:2(只剩x=1個(gè)數(shù)字)

第x=1個(gè)數(shù)為:2。

2:第二個(gè)結(jié)果:

當(dāng)n=4,x=2時(shí):

原始數(shù)字:1、2、3、4

第一步,去掉第一個(gè)數(shù)字:2、3、4

第二步,去掉第二個(gè)數(shù)字:2、4(只剩x=2個(gè)數(shù)字)

第x=2個(gè)數(shù)為:4。

3:第三個(gè)結(jié)果:

當(dāng)n=12,x=6時(shí):

原始數(shù)字:1、2、3、4、5、6、7、8、9、10、11、12

第一步,去掉第一個(gè)數(shù)字: 2、3、4、5、6、7、8、9、10、11、12

第二步,去掉第二個(gè)數(shù)字:2、4、5、6、7、8、9、10、11、12

第三步,去掉第三個(gè)數(shù)字:2、4、6、7、8、9、10、11、12

第四步,去掉第四個(gè)數(shù)字:2、4、6、8、9、10、11、12

第五步,去掉第五個(gè)數(shù)字:2、4、6、8、10、11、12

第六步,去掉第六個(gè)數(shù)字:2、4、6、8、10、12(只剩x=6個(gè)數(shù)字)

第x=6個(gè)數(shù)為:12。

可以看出:每次刪掉的都是奇數(shù),且依次從1、3、5、7……開(kāi)始刪,最終剩下的第x個(gè)數(shù)為2x,所以這道題超級(jí)簡(jiǎn)單


代碼如下:


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Lua 5.1 參考手冊(cè) by Roberto Ierusalimschy, Luiz Henrique de F...
    蘇黎九歌閱讀 14,246評(píng)論 0 38
  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類(lèi): pyspark.sql...
    mpro閱讀 9,912評(píng)論 0 13
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,847評(píng)論 0 10
  • 在C語(yǔ)言中,五種基本數(shù)據(jù)類(lèi)型存儲(chǔ)空間長(zhǎng)度的排列順序是: A)char B)char=int<=float C)ch...
    夏天再來(lái)閱讀 4,013評(píng)論 0 2
  • 因?yàn)椴粫?huì)做飯,我總是被公司的程序員小哥嘲笑,他說(shuō)他替我以后的老公感到難過(guò),或者我根本會(huì)因?yàn)椴粫?huì)做飯而嫁不出去。 和...
    王大純閱讀 793評(píng)論 2 7

友情鏈接更多精彩內(nèi)容