思維,暴力,打表

2022-05-23 16:30:14 字數 3545 閱讀 2756

題意:十進位制下,每相鄰兩個數字之間的差值不超過1,叫lunlun數,

給定乙個k,讓找第k小的lunlun數;

暴力打表找規律;

1,2,3,4,5,6,7,8,9,

10,11,12,

21,22,23,

32,33,34,

43,44,45,

54,55,56,

65,66,67,

76,77,78,

87,88,89,

98,99,

100,101,

110,111,112,

121,122,123,

210,211,212,

221,222,223,

232,233,234,

321,322,323,

332,333,334,

343,344,345,

432,433,434,

443,444,445,

454,455,456,

543,544,545,

554,555,556,

565,566,567,

654,655,656,

665,666,667,

676,677,678,

765,766,767,

776,777,778,

787,788,789,

876,877,878,

887,888,889,

898,899,

987,988,989,

998,999,

1000,1001,

1010,1011,1012,

1100,1101,

1110,1111,1112,

1121,1122,1123,

1210,1211,1212,

1221,1222,1223,

1232,1233,1234,

2100,2101,

2110,2111,2112,

2121,2122,2123,

2210,2211,2212,

2221,2222,2223,

2232,2233,2234,

2321,2322,2323,

2332,2333,2334,

2343,2344,2345,

3210,3211,3212,

3221,3222,3223,

3232,3233,3234,

3321,3322,3323,

3332,3333,3334,

3343,3344,3345,

3432,3433,3434,

3443,3444,3445,

3454,3455,3456,

4321,4322,4323,

4332,4333,4334,

4343,4344,4345,

4432,4433,4434,

4443,4444,4445,

4454,4455,4456,

4543,4544,4545,

4554,4555,4556,

4565,4566,4567,

5432,5433,5434,

5443,5444,5445,

5454,5455,5456,

5543,5544,5545,

5554,5555,5556,

5565,5566,5567,

5654,5655,5656,

5665,5666,5667,

5676,5677,5678,

6543,6544,6545,

6554,6555,6556,

6565,6566,6567,

6654,6655,6656,

6665,6666,6667,

6676,6677,6678,

6765,6766,6767,

6776,6777,6778,

6787,6788,6789,

7654,7655,7656,

7665,7666,7667,

7676,7677,7678,

7765,7766,7767,

7776,7777,7778,

7787,7788,7789,

7876,7877,7878,

7887,7888,7889,

7898,7899,

8765,8766,8767,

8776,8777,8778,

8787,8788,8789,

8876,8877,8878,

8887,8888,8889,

8898,8899,

8987,8988,8989,

8998,8999,

9876,9877,9878,

9887,9888,9889,

9898,9899,

9987,9988,9989,

9998,9999,

10000,10001,

10010,10011,10012,

10100,10101,

10110,10111,10112,

10121,10122,10123,

11000,11001,

11010,11011,11012,

11100,11101,

11110,11111,11112,

11121,11122,11123,

11210,11211,11212,

11221,11222,11223,

11232,11233,11234,

12100,12101,

12110,12111,12112,

........

如上表,可以發現;

末位的前一位為9,兩個數字98 99

末位前一位是10,兩個數字100 101

其他就三個數字;

找規律好之後,開乙個陣列,不斷計算出第k個數字即可;

code:

#include#include

using

namespace

std;

typedef

long

long

ll;const

int maxn=1e5+10;/*

int a[15];

int check(ll x)

for(i=2;i<=top;i++)

if(abs(a[i]-a[i-1])>1)return 0;

return 1;

}int main()

*/ll num[maxn]=;

intmain()

int cnt=0

;

for(int i=9; ielse

if(num[cnt]%10==9

)

else

cnt++;

}printf(

"%lld\n

",num[k-1

]);

//system("pause");

return0;

}

F Spy string(思維,暴力)

題意 給你n個長度為m的字串,要求你找出乙個字串,這個字串需要滿足與這n個字串的差別 字元不同 數最大為1,如果找不到則輸出 1。思路 既然我們要找到乙個字串,和每乙個字串的差別都小於等於1,那麼我們直接拿第乙個字串,對於每一位,從a到z列舉,如果列舉完了所有位,還找不到,那就找不到符合條件的串,因...

L Ray in the tube 思維 暴力

思路 思維 暴力。記 a b a,ba,b的橫座標距離為xxx。1.當x xx為奇數時,顯然x 1 x 1x 1包含所有奇數的情況。2.當x xx為偶數時,因為任何偶數質因數分解都可分解為 2k1 p2k 2 pm km 2 times p 2 dots p m 2k1 p 2k2 pm km 所以...

hdu 1443 Joseph 暴力打表

題目大意 k個好人,k個壞人,確定n,利用joseph方法刪除所有壞人.由於資料規模,可以利用暴力打表,以後能打表就盡量打表。這題原本模擬資料時間完全夠的,但是測試資料有很多重複的,導致很多人超時,暗坑!以後要注意點這種情況。打表 includeint main while scanf d n n ...