第一题AC(C++): # #include <vector> (7278)# #include <iostream> (5488)# #include <algorithm> using namespace std; void readCardCount(int n, vector<int> &cardCount) { cardCount.push_back(0); for (int i = 0; i < n; i++) { int card; cin >> card; if (card == 0) { cardCount.push_back(0); } else { ++cardCount.back(); } } } int maxCardLength(const vector<int> &cardCount) { int theMax = cardCount[0] - 1; for (int i = 1; i < cardCount.size(); i++) { theMax = max(theMax, cardCount[i - 1] + cardCount[i]); } return theMax; } int main() { int total_count; cin >> total_count; for (int i = 0; i < total_count; i++) { int n; cin >> n; vector<int> cardCount; readCardCount(n, cardCount); cout << maxCardLength(cardCount) << endl; } } 第二题给我干蒙了,感觉应该是DP或者贪心一类的东西,但是完全没有思路,那个4*10⁵暴力根本不可能过。
点赞 4

相关推荐

牛客网
牛客企业服务