2023年牛客寒假集訓營第六場題解

2021-10-20 09:34:50 字數 2652 閱讀 5264

a、回文括號序列計數

思路:只有 (…) 形式的才符合題意,但(…)不是回文串

所以只有0的時候才行,其他都不行

**:

#include

using

namespace std;

intmain()

return0;

}

c、末三位

思路:易得…

**:

#include

using

namespace std;

intmain()

return0;

}

d、劃數

思路:將所有除了 cnt 之外的數加起來取模即可,注意特判只有兩個數時的特殊情況

**:

#include

using

namespace std;

const

int n =

1e6+5;

int n, cnt;

int num[n]

;int

main()

if(n ==2)

num[k]=0

;for

(int i =

2; i <= n; i++

) cout << num[n]

<<

"\n";}

return0;

}

e、網格

思路:**:

f、組合數問題

思路:①打表上oies查詢(瞎搞)

②**:

#include

using

namespace std;

typedef

long

long ll;

const ll m =

998244353

;ll mod

(ll x, ll y)

ll qpow

(ll a, ll b)

return ans;

}int

main()

g、機械人

思路:因為n的範圍很小,所有可以用狀壓dp求出所有可能的組合順序的最大值,最終答案取值(20^20 < __int128),所以可用__int128代替高精度

**:

#include

using

namespace std;

const

int n =

20, m =

1<< n;

int a[n]

, b[n]

;__int128 f[m]

;inline

void

print

(__int128 x)

if(x >9)

print

(x/10);

putchar

(x%10

+'0');

}int

main()

print

(f[(

1<])

;return0;

}

i、貪吃蛇

思路:廣搜(bfs)板子題

**:

#include

using

namespace std;

int n, m;

int xs, ys, xe, ye;

char g[

105]

[105];

bool st[

105]

[105];

int xx=

;int yy=

;struct node

;int

main()

);while

(q.size()

)for

(int i =

0; i <

4; i++))

; st[dx]

[dy]=1

;}}puts

("-1");

return0;

}

j、天空之城

思路:最小生成樹板子題 + 雜湊儲存

**:

#include

using

namespace std;

#define int long long

const

int n =

5005

, inf =

0x3f3f3f3f

;int n, q, num, idx;

int g[n]

[n], dist[n]

;bool st[n]

;mapint> mp;

intget

(string s)

intprim()

return ans;

}signed

main()

int t =

prim()

;if(t == inf)

puts

("no!");

else

cout << t <<

"\n";}

return0;

}

2023年牛客寒假集訓營第五場題解

c 石子遊戲 思路 利用差分陣列將區間修改轉化為兩個端點處的單點修改,按照每次新增乙個長度為 k 的區間的規則,首先從左到右將所有點補到該點左邊比它高的點的高度,再從右到做將所有點補到該點右邊比它高的點的高度,最後特判一下第 n k 1 個點 因為差分時以該點為左端點的區間右端點無法判斷 然後如果能...

牛客寒假第六場 刪除子串行

給出乙個長度為nnn的字串sss和乙個長度為mmm的不含重複字元的字串ttt,每次你可以在sss中刪除乙個等於ttt的子串行,最多可以刪除多少次?如字串s ababccds ababccds ababccd,t abct abct abc,可以選擇s1s2s5,s1s2s6,s1s4s5,s1s4s...

2023年牛客寒假集訓營第二場題解

d 牛牛與整除分塊 思路 整數分塊有乙個性質,對於乙個整數n,當k n sqrt n 1 時,每個 n k 都是不同的,否則看n k是幾,然後利用對稱軸x n sqrt n 對稱過來 圖源自出題人 f 牛牛與交換排序 思路 如果有解的話k值一定是唯一的,那麼先確定k值,然後判斷這個k值是否可行。手寫...