牛客多校第三场A【Clam and fish】贪心
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.
总结:有鱼就抓(之前看直播讲题的时候这句话印象超深刻) 24dian(牛客多校第三场) 题意: 给你n张牌,每张牌的大小为1 ~ 13,问这些牌与加减乘除任意组合(可以使用括号),且但所有的有效解在计算过程中都涉及到分数,即非整数,能否组成答案m,如果可以 ... 牛客多校第三场 B[Classical String Problem] 链接:https://ac.nowcoder.com/acm/contest/5668/B 来源:牛客网 题目描述 Given ... 题目链接 题目大意:就是给你两个左右手的模型,下面给出这两只手通过平移变换之后坐标问你这只手是左手还是右手?[题目保证坐标是按照顺时针或者逆时针给出的] 解题思路:首先我们先观察一下这只右手:假如数据 ... 题目链接 题目大意:就是给你两个数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 ... 题目链接 题目大意: 就是每次把牌堆中若干个连续的牌放到堆顶,问你最后牌的序列. 解题思路: Splay 区间翻转的模板题: 对于一个区间[1,2,3,4,5,6,7,8][1,2,3,4,5,6,7 ... Math 题意: 问你有多少对(x,y),1<=x<=y<=n,满足(x2 + y2)%(xy+1) == 0 题解: 这种题...直接打表芜湖~ 通过打表发现:满足情况的为(i,i ... 题目链接 题目链接 题解 题面上面很明显的提示了需要严格\(O(n^3)\)的算法. 先考虑一个过不了的做法,枚举右下角的\((x,y)\),然后二分矩形面积,枚举其中一边,则复杂度是\(O(n^3 ... 题目链接:https://ac.nowcoder.com/acm/contest/883/B 题目大意 给定一个长度为 N 的 01 字符串,输出最长子串和子序列的长度,满足其中 0 和 1 的个数相 ... A Ancestor 题意:给出两棵 nnn 个节点的树 A,BA,BA,B,A,BA,BA,B 树上每个节点均有一个权值,给出 kkk 个关键点的编号 x1,x2,⋯,xkx_1, x_2, \cd ...
就是2 3这两种情况,直接fish++就好,碰到0,有饵就fish++,碰到1就bait++。最后sum=fish+bait/2;(/2的意义就是:举个例子,11两次,一次制饵一次钓鱼是获得
牛客多校第三场A【Clam and fish】贪心相关推荐
最新文章
热门文章