wzoi(栈模拟)

链接:https://ac.nowcoder.com/acm/contest/332/I
来源:牛客网
 

题目描述

bleaves 最近在 wzoi 上面做题。
wzoi 的题目有两种,一种是 noip 题,一种是省选题。
bleaves 的做题方式很特别。每一天,她可能会看一道题目,这时她会选择题目种类,然后 wzoi 会在选定种类中随机扔给她一道她还没看过的题,她会把这道题看一遍,然后存在脑子里慢慢思考;她也有可能写题,这时她一定会写没写过的题中看的时间最迟的一题(如果不存在没写过的且没看过的题,她就不能写题)。
wzoi 每天会有一个推荐的题目种类,
如果 bleaves 看一道题目:如果种类和推荐的相同,那么这道题目最大得分为10,否则为5
如果 bleaves 写一道题目:如果种类和推荐的相同,那么这道题目得分为最大得分,否则为最大得分-5
假如 bleaves 现在还没看过任何一题,并且她知道了 wzoi 接下来一些天每天推荐的种类,问她在这些天的最大得分。

输入描述:

一行一个01串 s ,|s| 表示天数,si=0si=0 表示 wzoi 第 i 天推荐 noip 题, si=1si=1 表示 wzoi 第 i 天推荐省选题。

输出描述:

一行一个整数最大得分。

示例1

输入

复制

0011

输出

复制

20

说明

4天行动依次为:看一道 noip 题,写第1天看的题,看一道省选题,写第3天看的题。

示例2

输入

复制

0101

输出

复制

10

说明

4天行动依次为:看一道 noip 题,写第1天看的题,看一道noip题,写第3天看的题。

示例3

输入

复制

0110

输出

复制

20

说明

4天行动依次为:看一道 noip 题,看一道省选题,写第2天看的题,写第1天看的题。

备注:

全部的输入数据满足:1≤n≤1061≤n≤106 , n 为偶数。

用栈模拟一下就ok,和之前的cf题有点类似

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
/*10100
10101*/
stack<char>s;
char a[1000005];
int cnt=1;
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    s.push(a[0]);
    ll sum=0;
    for(int t=1;t<len;t++)
    {
    	if(s.empty())
    	{
    		s.push(a[t]);
			continue; 
		}
    	if(a[t]==s.top()&&!s.empty())
    	{
//    		cout<<s.top()<<endl; 
    		s.pop();
    		sum+=10;
		}
		else if(a[t]!=s.top()&&!s.empty())
		{
			s.push(a[t]);
		
			
		}
		
	}
	while(!s.empty())
	{
		s.pop();
		s.pop();
		sum+=5;
	}
	printf("%lld",sum);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lbperfect123/article/details/86751588
今日推荐