A【Clam and fish】贪心

链接:https://ac.nowcoder.com/acm/contest/5668/A
来源:牛客网
题目:
There is a fishing game as following:

The game contains nn stages, numbered from 11 to nn.

There are four types of stages (numbered from 00 to 33):

type 00: There are no fish and no clam in this stage.

type 11: There are no fish and one clam in this stage.

type 22: There are one fish and no clam in this stage.

type 33: There are one fish and one clam in this stage.

In each stage, you can do exactly one of the following four actions.

If there is a clam in the stage, you can use this clam to make one pack of fish bait. And the number of packs of fish bait you have is increased by one. You can use this pack of fish bait to catch fish after this stage.

If there is one fish in the stage, you can catch this fish without any fish bait. After this stage, the number of packs of fish bait you have is not changed.

If you have at least one pack of fish bait. You can always catch one fish by using exactly one pack of fish bait even if there are no fish in this stage. After this stage, the number of packs of fish bait you have is decreased by one.

You can do nothing.

Now, you are given nn and the type of each stage. Please calculate the largest number of fish you can get in the fishing game.

输入描述:
The first line contains one integer t (1 \le t \le 2.5 \times 10^51≤t≤2.5×10
5
) — the number of test cases.

There are two lines in each test. The first line contains one integer n (1 \le n \le 2 \times 10^61≤n≤2×10
6
), indicating the number of stages in this game. The second line contains a string with length n. The i-th character of this string indicates the type of the i-th stage.

The sum of n across the test cases doesn’t exceed 2 \times 10^62×10
6
.
输出描述:
For each test case print exactly one integer — the maximum number of fish you can catch in the game configuration.
示例1

输入
2
4
0103
1
1
输出
2
0
备注:
One possible scenario you can catch two fishes is as follow:

stage 1: Do nothing.
stage 2: Make a pack of fish bait.
stage 3: Catch a fish by a pack of fish bait.
stage 4: Catch the fish that appears in the stage.

总结:有鱼就抓(之前看直播讲题的时候这句话印象超深刻)
就是2 3这两种情况,直接fish++就好,碰到0,有饵就fish++,碰到1就bait++。最后sum=fish+bait/2;(/2的意义就是:举个例子,11两次,一次制饵一次钓鱼是获得

牛客多校第三场A【Clam and fish】贪心相关推荐

  1. 24dian(牛客多校第三场)

    24dian(牛客多校第三场) 题意: 给你n张牌,每张牌的大小为1 ~ 13,问这些牌与加减乘除任意组合(可以使用括号),且但所有的有效解在计算过程中都涉及到分数,即非整数,能否组成答案m,如果可以 ...

  2. 牛客多校第三场 B【Classical String Problem】

    牛客多校第三场 B[Classical String Problem] 链接:https://ac.nowcoder.com/acm/contest/5668/B 来源:牛客网 题目描述 Given ...

  3. 2020牛客多校第三场[C Operation Love+基础计算几何 判断多边形顺逆时针]

    题目链接 题目大意:就是给你两个左右手的模型,下面给出这两只手通过平移变换之后坐标问你这只手是左手还是右手?[题目保证坐标是按照顺时针或者逆时针给出的] 解题思路:首先我们先观察一下这只右手:假如数据 ...

  4. exgcd ---- 2020牛客多校第三场:[Fraction Construction Problem:exgcd+思维题]

    题目链接 题目大意:就是给你两个数a,ba,ba,b叫你求满足下面三个条件的c,d,e,fc,d,e,fc,d,e,f 1.cd−ef=ab1.{c\over d}-{e\over f}={a\ove ...

  5. Splay ---- 2018牛客多校第三场 区间翻转搞区间位移 或者 rope可持久化块状链表

    题目链接 题目大意: 就是每次把牌堆中若干个连续的牌放到堆顶,问你最后牌的序列. 解题思路: Splay 区间翻转的模板题: 对于一个区间[1,2,3,4,5,6,7,8][1,2,3,4,5,6,7 ...

  6. Math(牛客多校第三场)

    Math 题意: 问你有多少对(x,y),1<=x<=y<=n,满足(x2 + y2)%(xy+1) == 0 题解: 这种题...直接打表芜湖~ 通过打表发现:满足情况的为(i,i ...

  7. 2019牛客多校第三场 F.Planting Trees

    题目链接 题目链接 题解 题面上面很明显的提示了需要严格\(O(n^3)\)的算法. 先考虑一个过不了的做法,枚举右下角的\((x,y)\),然后二分矩形面积,枚举其中一边,则复杂度是\(O(n^3 ...

  8. 2019 牛客多校第三场 B Crazy Binary String

    题目链接:https://ac.nowcoder.com/acm/contest/883/B 题目大意 给定一个长度为 N 的 01 字符串,输出最长子串和子序列的长度,满足其中 0 和 1 的个数相 ...

  9. 2022年牛客多校第三场补题记录

    A Ancestor 题意:给出两棵 nnn 个节点的树 A,BA,BA,B,A,BA,BA,B 树上每个节点均有一个权值,给出 kkk 个关键点的编号 x1,x2,⋯,xkx_1, x_2, \cd ...

最新文章

  1. php帝国系统调出图片内空,帝国CMS图集字段的大图,小图,说明的调用方法
  2. 线下活动【深圳】用Leangoo做Scrum敏捷开发实战课(免费)
  3. 使用apache的ab对想迪科技站点www.thinkdee.com进行压力测试
  4. Tornado源码分析 --- 静态文件处理模块
  5. 【MRCTF—Web】做题+复现记录
  6. win8.1平板安装ubuntu16.04的折腾
  7. 《ASP.NET Core 微服务实战》送书结果公告
  8. 简单的python画图代码_python opencv如何实现简易画图板 python opencv实现简易画图板代码...
  9. mysql 分享_雷林鹏分享:MySQL 连接
  10. Python 自带的 any() 函数--判断给定的可迭代参数 iterable 是否全部为 False
  11. 错误:Type javax.xml.bind.JAXBContext not present
  12. html css:背景图片链接css写法
  13. TI DSP C64X 优化基本方法
  14. springboot集成socket.io通过jwt-token身份认证鉴权
  15. 第二讲:云分类及服务模式
  16. 固态硬盘计算机怎么自定义分区,如何设置SSD固态硬盘为主硬盘 怎样把SSD分区设置成主分区?...
  17. 微信小程序:上传的图片显示旋转问题
  18. Juniper JUNOS Commands (Tips and Tricks)
  19. “Random“ objects should be reused解决 Random() 低效问题
  20. 微信流量主点击量与曝光量是什么意思

热门文章

  1. 睡眠的一场革命!-读《睡眠革命》笔记(上)
  2. 多线程的实际应用-生产者与消费者的例子
  3. Kafka Java客户端Stream API
  4. 【Spring Cloud 4,【一步教学,一步到位】
  5. 重庆北大青鸟解放碑校区 J11班 人均一米八队 【一站式生活服务平台】
  6. unity怎么显示骨骼_浅谈Unity3D 骨骼动画
  7. ubuntu 编译 jdk (二)
  8. GetCurrentProcess()方法进程资源查询实例
  9. 如何在服务器上做磁盘阵列
  10. Google原生输入法LatinIME词库构建流程分析(三)--N-gram信息构建