C. Mortal Kombat Tower Educational Codeforces Round 95 (Rated for Div. 2)

You and your friend are playing the game Mortal Kombat XI. You are trying to pass a challenge tower. There are n� bosses in this tower, numbered from 11 to n�. The type of the i�-th boss is ai��. If the i�-th boss is easy then its type is ai=0��=0, otherwise this boss is hard and its type is ai=1��=1.

During one session, either you or your friend can kill one or two bosses (neither you nor your friend can skip the session, so the minimum number of bosses killed during one session is at least one). After your friend session, your session begins, then again your friend session begins, your session begins, and so on. The first session is your friend's session.

Your friend needs to get good because he can't actually kill hard bosses. To kill them, he uses skip points. One skip point can be used to kill one hard boss.

Your task is to find the minimum number of skip points your friend needs to use so you and your friend kill all n� bosses in the given order.

For example: suppose n=8�=8, a=[1,0,1,1,0,1,1,1]�=[1,0,1,1,0,1,1,1]. Then the best course of action is the following:

  • your friend kills two first bosses, using one skip point for the first boss;
  • you kill the third and the fourth bosses;
  • your friend kills the fifth boss;
  • you kill the sixth and the seventh bosses;
  • your friend kills the last boss, using one skip point, so the tower is completed using two skip points.

You have to answer t� independent test cases.

Input

The first line of the input contains one integer t� (1≤t≤2⋅1041≤�≤2⋅104) — the number of test cases. Then t� test cases follow.

The first line of the test case contains one integer n� (1≤n≤2⋅1051≤�≤2⋅105) — the number of bosses. The second line of the test case contains n� integers a1,a2,…,an�1,�2,…,�� (0≤ai≤10≤��≤1), where ai�� is the type of the i�-th boss.

It is guaranteed that the sum of n� does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑�≤2⋅105).

Output

For each test case, print the answer: the minimum number of skip points your friend needs to use so you and your friend kill all n� bosses in the given order.

Example

input

6
8
1 0 1 1 0 1 1 1
5
1 1 1 1 0
7
1 1 1 1 0 0 1
6
1 1 1 1 1 1
1
1
1
0

output

2
2
2
2
1
0

题目大意:

我和朋友玩游戏,朋友遇到1的怪只能跳过,我可以杀掉1或0的怪,我和朋友能杀一个或两个怪,但不能不杀,问朋友最少跳几次?

思路:

分析一下在什么情况下朋友不得不跳:

1、第一个怪就是1。

2、连着3个怪是1。

 方法:

跑单for查看有多少连着的1。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

void solve(){
	ll x,op,cnt=0,sum=0;
	cin >> op >> sum;
	op--;
	while(op--){
		cin >> x;
		if(x)cnt ++;
		else sum = sum+(cnt/3),cnt=0;
	}
	cout << sum+(cnt/3) << endl;
	return ;
}

int main(){
	ll t=1;cin >> t;
	while(t --)solve();
	return 0;
}
  • 14
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你的问题是关于一个类层次结构的定义。这里给出一个 Java 代码示例: ```java // 定义人类,具有基本的吃和睡行为 class Human { public void eat() { System.out.println("Human eat"); } public void sleep() { System.out.println("Human sleep"); } } // 定义可以做梦的行为物体 interface Dreamable { public void dream(); } // 定义可以飞行的行为物体 interface Flyable { public void fly(); } // 定义超人类,继承自人类,具有飞行技能 class Superman extends Human implements Flyable { public void fly() { System.out.println("Superman fly"); } } // 定义凡人类,继承自人类,具有做梦技能 class Mortal extends Human implements Dreamable { public void dream() { System.out.println("Mortal dream"); } } // 定义大鸟类,实现飞行接口 class Eagle implements Flyable { public void fly() { System.out.println("Eagle fly"); } } // 测试类 public class Test { public static void main(String[] args) { // 构建凡人对象 Mortal mortal = new Mortal(); mortal.eat(); mortal.sleep(); mortal.dream(); // 构建会飞的对象数组 Flyable[] flyables = new Flyable[] {new Eagle(), new Superman()}; // 打印数组中各对象的状态 for (Flyable f : flyables) { if (f instanceof Eagle) { System.out.println("This is an Eagle."); } else if (f instanceof Superman) { System.out.println("This is a Superman."); } f.fly(); } } } ``` 注意,在 `Test` 类的 `main` 方法中,我们首先构建了一个凡人对象 `mortal`,并调用了其吃、睡、做梦的方法。然后,我们构建了一个会飞的对象数组 `flyables`,其中包含一个大鸟对象和一个超人对象。我们通过遍历数组中的每个元素,并使用 `instanceof` 运算符判断其类型,来打印数组中各对象的状态。最后,我们调用每个对象的飞行方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值