• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

CodeForces 688A-Opponents

题意:
  Arya在学校有n个敌人(一串含有0,1的数字表示),有一个游戏规则,如果当天这n个敌人全部出席("1"代表出席,),即这串数字全部为"1",则Arya就输了,
否则,只要其中就一个"0",代表Arya赢,问你他连续赢得最多的天数?

分析:
  初始化ans(连续赢得最多的天数)为0,Arya连续赢天数day就加1,否则比较day与ans大小,ans = max(ans, day);

 

 

 

 

 

代码如下:

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector>

using namespace std;

#define LL long long
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 10000010
#define MAXM 1000010

int main()
{
    int d;
    int n;
    int cnt, flag, pos;
    while(cin>>n>>d)
    {
        string s;
        int i, j;
        pos = 0;
        cnt = 0;
        for(i = 1; i <= d; i++ )
        {
            flag = 0;
            cin>>s;
            for(j = 0; j < n; j++ )
            {
                if(s[j]-'0' == 0)
                {
                    flag = 1;
                    break;
                }
            }
            if(flag)
            {
                cnt += 1;
                pos = max(pos, cnt);
            }
            else 
                cnt = 0;
        }
        printf("%d\n", pos);
    }
    return 0;
}

  

 

posted on 2016-07-14 10:57  tony-cao  阅读(174)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3