codeforces-#465B. Inbox (100500)(模拟)

来源:互联网 发布:阿里巴巴标题优化技巧 编辑:程序博客网 时间:2024/06/01 09:35

       题目大意:给出邮件箱已读和未读的邮件状态以及分布情况,求最少还需要点击多少次才能读完。

      解题思路:模拟裸题,直接按照题目的要求进行模拟即可,注意末尾有0的判断,这里输入的时候记下所有的1,然后后面有两个0的时候,直接看1被读完没?没读完则说明要点击返回列表继续,需要加加,否则不加。

     题目来源:http://codeforces.com/problemset/problem/465/B

     code:

#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN =1000+10;int n,ans;int str[MAXN];int main(){    while(scanf("%d",&n)!=EOF){        ans=0;        int k=0,count=0;        memset(str,0,sizeof(str));        for(int i=0;i<n;i++){            scanf("%d",&str[i]);            if(str[i]==1) count++;        }        for(int i=0;i<n;){            if(str[i]==1){                ans++;                k++;                if(str[i+1]==0 && str[i+1]==1){                    ans++;i+=2;                }                if(str[i+1]==0 && str[i+1]==0 && count!=k){                    ans++;i+=2;                }                else i++;            }            else i++;        }        printf("%d\n",ans);    }    return 0;}

0 0
原创粉丝点击