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

2021-10-19 05:25:42 字數 3281 閱讀 8699

三場牛客下來覺得自己越來越不在狀態,思路不清晰,一下手就是bug,每調完一題刷下榜都被甩開十里地,罰時慘不忍睹

傳送門

簽到

#include using namespace std;

typedef long long ll;

const ll inf = 0x3f3f3f3f;

const ll mod = 1000000007;

const ll n = 4e6 + 7;

int main()

for(int i = n + 1; ; ++i)

if(cnt == sum)

}return 0;

}

傳送門

同一連通塊中的小朋友的糖數必定相同且為他們中最大的需求值。

邊沒必要去重,憨批一樣白給了一發

#include using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;

const int mod = 1000000007;

const int n = 1e6 + 7;

inline int read()

while(isdigit(ch))

return x * f;

}int a[n], n, m, maxx, cnt;

bool vis[n];

vectormp[n];

void dfs(int u)

}int main()

for(int i = 1; i <= n; ++i) vis[i] = 0;

ll ans = 0;

for(int i = 1; i <= n; ++i)

printf("%lld\n", ans);

return 0;

}

傳送門

把除 j = 10、t = 20之外的乙個 > j 的字母拆成倆即可,如果沒有這樣的字母,找是否有兩個字母可以合成乙個,注意 j、t 不可更改且不可合併

#include using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;

const int mod = 1000000007;

const int n = 1e6 + 7;

int main()

else str += s[i];

}if(!flag)

}if(id == -1)

for(int i = 0; i < n; ++i)

cout << '\n';

}else cout << str << '\n';

return 0;

}

傳送門

直接順序更新答案,las[x] 記錄 x 上一次出現時的答案,掃到第 i 個位置時,首先判斷a[i]是否等於a[i - 1],是則答案++,然後判斷 las[a[i]] 和當前答案的關係,若二者相等,說明上乙個數a[i]出現的位置和當前位置之間的這一段序列沒有任何貢獻,還不如把它們刪掉讓兩個a[i]靠著貢獻1,所以此時答案++,更新las[a[i]]

賽時思路極其不清晰 4wa

#include using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;

const int mod = 1000000007;

const int n = 1e6 + 7;

int a[n], las[n];

int main()

printf("%d\n", cnt);

return 0;

}

傳送門

奇 + 奇 = 偶,奇 * 奇 = 奇

奇 + 偶 = 奇,奇 * 偶 = 偶

偶 + 偶 = 偶,偶 * 偶 = 偶

牛妹總能將任意兩個數變成偶數,如果最後一步是牛妹,即n是奇數,則牛妹必勝

牛牛要變出乙個奇數的前提是兩個數中至少要有乙個奇數,所以牛妹會在每次操作盡量消除奇數,牛牛會盡量消除偶數,牛妹的每次操作最多消除兩個奇數,增加乙個偶數,而牛牛最多消除乙個偶數,可以發現如果原序列中多於乙個偶數,到最後不會剩下奇數,所以牛牛贏的條件是n 是偶數且數列中<=1個偶數

特判特判特判 n == 1!!!

#include using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;

const int mod = 1000000007;

const int n = 1e6 + 7;

int main()

if(n == 1)

else

return 0;

}

傳送門

判斷n個字串的首尾是不是有矛盾的,沒有矛盾都是無窮個

鑑於罰時已經無可救藥,樣例過了就交了,沒想到1a

#include using namespace std;

typedef long long ll;

const int inf = 0x3f3f3f3f;

const int mod = 1000000007;

const int n = 1e6 + 7;

int be[n], ed[n];

string s[n];

int main()

break;}}

for(int j = len - 1; j >= 0; --j) s[12];

bitset<12>bit[n];

bool check(node a, node b)

int op = 7;

int main() , s[i])) bit[tot].set(i);}}

int ans = 0;

for(int i = 1; i <= tot; ++i)

for(int j = i + 1; j <= tot; ++j)

for(int k = j + 1; k <= tot; ++k) }}

printf("%d\n", ans);

return 0;

}

還沒補完,南京站以來懈怠了很多,手生了不少,忙活這忙活那,就是沒有沉下心來,浪費了乙個月。明天補完,cf我來啦!!!

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

題目描述 請你構造乙個非空的括號字串,包含正好 k 個不同合法括號對。所謂括號字串,是指由 和 這兩種字元構成的字串。要求構造的字串長度不超過100000。輸入描述 乙個整數 k。乙個整數 kk。0 k 1e9 輸出描述 乙個僅包含左右括號字串,其中有 kk 個合法的括號對。如果有多種構造方法,輸出...

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

思路 k1排k2前面滿足 k1.a k2.ax k2.b k1.b k1.ax k1.b k2.b k2.ak1.b k2.b k1.a k2.a k1.b include define ull unsigned long long define ll long long const int inf...

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

c.重力墜擊 題解 1.深搜。注意要避免某些圓被多次相交時重複計數的情況。2.暴力。列舉每個圓心相交的圓的數量,存到降序排列的優先佇列中,取前k個即可。include using namespace std struct node a 20 pos 20 int n,k,r int mx bool ...