【CodeForces】Codeforces Round 857 (Div. 2) B

简介: 【CodeForces】Codeforces Round 857 (Div. 2) B

Dashboard - Codeforces Round 857 (Div. 2) - Codeforces


根据我的经验,cf的A题,有时候看给出的样例就能a出来,那么a题就不记录了😉


下面是B题


Problem - B - Codeforces

12.3.png

12.4.png

这种长文字的题,建议先用翻译工具翻译(虽然有可能不准确),了解个大概,然后再处理细节

这样可以节约时间

#include<iostream>
using namespace std;
#define ll long long
const int N=10010;
int a[N];
int main()
{
  int t;
  cin>>t;
  while(t--)
  {
    ll n;
    ll ans = 0, pigs = 0, cages = 0;
      cin >> n;
      for(int i=0;i<n;i++)
    {
      cin>>a[i];
      if (a[i] == 1)
          {
              pigs++;
              cages++;
          }
          else
          {
              if (pigs != 0)//关键点
              {
                  cages = pigs / 2 + 1;
              }
          }
              ans = max(ans, cages);
    }     
      cout << ans << endl;
  }
}

Code over!

相关文章
|
10月前
|
人工智能
Codeforces Round #786 (Div. 3)(A-D)
Codeforces Round #786 (Div. 3)(A-D)
56 0
Codeforces Round 799 (Div. 4)
Codeforces Round 799 (Div. 4)
95 0
|
人工智能 索引
Codeforces Round 806 (Div. 4)
Codeforces Round 806 (Div. 4)A~G
94 0
|
人工智能 算法