補題 牛客寒假演算法基礎集訓營1

2021-10-02 14:21:39 字數 4748 閱讀 9375

h nozomi和字串

做法:用兩個佇列,通過維護size+k大小的滑動視窗更新答案。

**

#include

#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define lson rt<<1, l, mid

#define rson rt<<1|1, mid+1, r

using

namespace std;

typedef

long

long ll;

typedef pairint> pli;

typedef pair<

int,

int> pii;

typedef pair pll;

typedef pair<

double

,double

> pdd;

typedef map<

char

,int

> mci;

typedef mapint> msi;

template

<

class

t>

void

read

(t &res)

while

(c >=

'0'&& c <=

'9')

res *

= f;

}queue<

int> q[2]

;int

main()

if(res > n) res = n;

cout << res << endl;

return0;

}

i nico和niconiconi

做法:簡單dp遞推一下就好啦…當時怎麼就沒看這題呢…

**

#include

#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define lson rt<<1, l, mid

#define rson rt<<1|1, mid+1, r

using

namespace std;

typedef

long

long ll;

typedef pairint> pli;

typedef pair<

int,

int> pii;

typedef pair pll;

typedef pair<

double

,double

> pdd;

typedef map<

char

,int

> mci;

typedef mapint> msi;

template

<

class

t>

void

read

(t &res)

while

(c >=

'0'&& c <=

'9')

res *

= f;

}const

int n =

3e5+5;

ll dp[n]

;int

main()

cout << dp[n-1]

<< endl;

return0;

}

j u』s的影響力

做法:思路很簡單,指數取模mod-1就行,因為0次方時要輸出0總是90分過不去…細節問題比較多

**

#include

#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define lson rt<<1, l, mid

#define rson rt<<1|1, mid+1, r

using

namespace std;

typedef

long

long ll;

typedef pairint> pli;

typedef pair<

int,

int> pii;

typedef pair pll;

typedef pair<

double

,double

> pdd;

typedef map<

char

,int

> mci;

typedef mapint> msi;

template

<

class

t>

void

read

(t &res)

while

(c >=

'0'&& c <=

'9')

res *

= f;

}const

int maxn =4;

const ll mod =

1e9+7;

struct mat };

mat matmul

(mat a,mat b)}}

return ans;

}mat quickpow

(mat a,ll n)

return res;

}ll ksm

(ll x, ll n)

return sum;

}int

main()

if(n ==2)

mat mid, res;

ll res1, res2, res3;

mid.m[1]

[1]= mid.m[1]

[2]= mid.m[1]

[3]= mid.m[2]

[1]= mid.m[3]

[3]=

1;res =

quickpow

(mid, n-2)

; res1 = res.m[1]

[2]; res2 = res.m[1]

[1]; res3 = res.m[1]

[3];

cout <<

ksm(x, res1)

*ksm

(y, res2)

% mod *

ksm(

ksm(a, b)

, res3)

% mod << endl;

return0;

}

f maki和tree

做法:有兩種情況,端點為白點和白點,白點和黑點,把黑點周圍的白點連通塊sum求出來,第一種的結果用容斥得到,為該黑點周圍白點連通塊任意兩白點構成的數量減去單個連通塊內的任意兩白點構成的數量(這裡的端點為兩白點的就不經過黑點了),第二種就是sum啦…

**

#include

#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define lson rt<<1, l, mid

#define rson rt<<1|1, mid+1, r

using

namespace std;

typedef

long

long ll;

typedef pairint> pli;

typedef pair<

int,

int> pii;

typedef pair pll;

typedef pair<

double

,double

> pdd;

typedef map<

char

,int

> mci;

typedef mapint> msi;

template

<

class

t>

void

read

(t &res)

while

(c >=

'0'&& c <=

'9')

res *

= f;

}const

int n =

1e5+5;

ll sum, ans, t1, t2;

char s[n]

;vector<

int> ve[n]

;void

dfs(

int u,

int fa)

}int

main()

for(

int i =

1; i <= n;

++i)

ans +

=(t1 * t1 - t2)/2

;}printf

("%lld\n"

, ans)

;return0;

}

c umi和弓道

做法:是個滑動視窗??

2021牛客寒假演算法基礎集訓營1 補題報告

長度不超過nn,且包含子串行 us 的 只由小寫字母構成的字串有多少個?答案對1e9 7 1e9 7 1e9 7取模。所謂子串行,指乙個字串刪除部分字元 也可以不刪 得到的字串。例如,unoacscc 包含子串行 us 但 scscucu 則不包含子串行 us 乙個正整數n,2 n 106 n,2 ...

2021牛客寒假演算法基礎集訓營1 解題補題報告

官方題解 記 dp i 為長度為 i 且包含 us 的字串的總數量,接下來我們考慮遞推關係 如果前 i 1 項中已經含有 us 那麼第 i 項什麼都行,總計 26 dp i 1 如果前 i 1 項裡面只有 u 那麼第 i 項必須為 s 我們考慮下前 i 1 項裡面只有 u 沒有 s 的情況 總計可以...

牛客寒假演算法基礎集訓營1

菜雞乙個,只做出兩道,先掛一下,剩下的會了繼續更 1 小a的計算器 題目描述 小a的數學基礎實在太差了,以至於他只會用計算器算數。他的計算器比較特殊,只有 即加減乘除 四種運算。經過一番周折,小a終於算出了他想要的數,但是他卻忘記了最初的數是什麼。不過幸運的是他記下了整個操作序列,他想請你幫他算出最...