2018年全國多校算法寒假訓練營練習比賽(第二場)
阿新 • • 發佈:2018-01-28
組成 滿足 targe ring1 例如 爐石傳說 oooo 曲線 更多
A題:
鏈接:https://www.nowcoder.com/acm/contest/74/A
來源:牛客網
小魚兒吐泡泡,嘟嘟嘟冒出來。小魚兒會吐出兩種泡泡:大泡泡"O",小泡泡"o"。 兩個相鄰的小泡泡會融成一個大泡泡,兩個相鄰的大泡泡會爆掉。 (是的你沒看錯,小氣泡和大氣泡不會產生任何變化的,原因我也不知道。) 例如:ooOOoooO經過一段時間以後會變成oO。
輸入描述:
數據有多組,處理到文件結束。
每組輸入包含一行僅有‘O‘與‘o‘組成的字符串。
輸出描述:
每組輸出僅包含一行,輸出一行字符串代表小魚兒吐出的泡泡經過融合以後所剩余的泡泡。示例1
輸入
ooOOoooO
輸出
oO
說明
自左到右進行合並
備註:
對於100%的數據,
字符串的長度不超過100。
#include<bits/stdc++.h> using namespace std; //const int INF =0x3f3f3f3f; //int SUM[1005][1005]; //int dp[1005][1005]; int dp[105]; int main() { string s; while(cin >> s) { string string1 = ""; for(int i=0;i < s.length();i++) { string1= s[i] + string1; } int lens = string1.length(); int t = lens; while(1) { if(t == 0) break; if(string1[t-1] == string1[t-2]) { if(string1[t-1] == ‘o‘) { if(t < string1.length()) { string stemp = string1.substr(t,string1.length()-t); string1 = string1.substr(0,t-2); string1 += ‘O‘; string1 += stemp; t = string1.length(); } else { string1 = string1.substr(0,t-2); string1 += ‘O‘; t = string1.length(); } } else if(string1[t-1] == ‘O‘) { if(t < string1.length()) { string stemp = string1.substr(t,string1.length()-t); string1 = string1.substr(0,t-2); string1 += stemp; t = string1.length(); } else { string1 = string1.substr(0,t-2); t = string1.length(); } } } else { t = t-1; } } string string2 = ""; for(int i=0;i < string1.length();i++) { string2 = string1[i] + string2; } cout << string2 << endl; } return 0; }
寫了一個h,長長一坨。
B題
鏈接:https://www.nowcoder.com/acm/contest/74/D
來源:牛客網
題目描述
Wozuinb非常喜歡打爐石傳說,但是菜的不行,所以他決定打 競技場來練練手。系統按順序給出n張卡牌,每張卡牌都有自 己的使用消耗a[i],每次只給出一張,wozuinb可以選擇或者 棄掉這張牌。每選擇一張牌都會按選擇順序放在卡槽中,當 卡槽中放滿30張即可組成一套套牌。Wozuinb希望自己的套牌的 消耗滿足一個平滑的曲線,即30張卡牌都滿足第i張卡牌的消耗 不小於第i-1張(i>1)。請你幫助wozuinb看一看,這些卡牌能不 能組成想要的套牌,如果能組成輸出“yes”,如果不能輸出“no”。
輸入描述:
第一行輸入一個整數n,0<n<100。
第二行輸入一行數字a[i],每個數字用空格隔開,代表第i張出現的卡牌的消耗。
輸出描述:
輸出一行,“yes”或“no”示例1
輸入
5 1 2 3 4 5
輸出
no
#include<bits/stdc++.h> using namespace std; //const int INF =0x3f3f3f3f; //int SUM[1005][1005]; //int dp[1005][1005]; int dp[105]; int main() { int n; cin >> n; int a[105]; for(int i=0;i < 105;i++) dp[i] = 1; for(int i=1;i <= n;i++) cin >> a[i]; for(int i=1;i <= n;i++) { for(int j=1;j < i;j++) { if(a[i] >= a[j]) { dp[i] = max(dp[i],dp[j]+1); } } } int ans = 0; for(int i=1;i <= n;i++) { ans = max(ans,dp[i]); } if(ans >= 30) cout << "yes" << endl; else cout << "no" << endl; return 0; }
最長不下降子序列裸題。
H題
鏈接:https://www.nowcoder.com/acm/contest/74/H
來源:牛客網
題目描述
既然是了斷局了,大家就隨便玩玩數字唄。 已知一個數列前10項分別是 {0, 1, 1, 2, 4, 7, 13, 24, 44, 81} 小G不滿足呀:我要更多的數!!!不給就不讓你們玩了。 小G會問你第n項是什麽數字,請回答這個頑皮的孩子吧。
輸入描述:
多組數據輸入輸出;
第一行輸入一個整數n(1<=n<=50)
輸出描述:
輸出數列中的第n個數。示例1
輸入
1 2 3
輸出
0 1 1
#include<bits/stdc++.h> using namespace std; //const int INF =0x3f3f3f3f; //int SUM[1005][1005]; //int dp[1005][1005]; int main() { long long a[55]; a[1] = 0; a[2] = 1; a[3] = 1; for(int i=4;i <= 54;i++) { a[i] = a[i-3] + a[i-2] + a[i-1]; } int n; while(cin >> n) { cout << a[n] << endl; } return 0; }
找規律+longlong
只寫了3題,太菜了,日後補題。
2018年全國多校算法寒假訓練營練習比賽(第二場)