CF--1649A. Game

本文介绍了一个关于计算机游戏中的关卡设计问题,玩家需要从第一个到最后一个地点,中间可能包含陆地和水域。玩家只能在陆地上移动,并且可以进行跳跃,但需要消耗金币。每个跳跃可以跳过最多x个位置。任务是找出从起点到终点所需的最低金币数。通过示例解释了如何计算最短路径,并提供了解决方案的代码实现。

You are playing a very popular computer game. The next level consists of nn consecutive locations, numbered from 11 to nn, each of them containing either land or water. It is known that the first and last locations contain land, and for completing the level you have to move from the first location to the last. Also, if you become inside a location with water, you will die, so you can only move between locations with land.

You can jump between adjacent locations for free, as well as no more than once jump from any location with land ii to any location with land i + xi+x, spending xx coins (x \geq 0x≥0).

Your task is to spend the minimum possible number of coins to move from the first location to the last one.

Note that this is always possible since both the first and last locations are the land locations.

Input

There are several test cases in the input data. The first line contains a single integer tt (1 \leq t \leq 1001≤t≤100) — the number of test cases. This is followed by the test cases description.

The first line of each test case contains one integer nn (2 \leq n \leq 1002≤n≤100) — the number of locations.

The second line of the test case contains a sequence of integers a_1, a_2, \ldots, a_na1​,a2​,…,an​ (0 \leq a_i \leq 10≤ai​≤1), where a_i = 1ai​=1 means that the ii-th location is the location with land, and a_i = 0ai​=0 means that the ii-th location is the location with water. It is guaranteed that a_1 = 1a1​=1 and a_n = 1an​=1.

Output

For each test case print a single integer — the answer to the problem.

Sample 1

InputcopyOutputcopy
3
2
1 1
5
1 0 1 0 1
4
1 0 1 1
0
4
2

Note

In the first test case, it is enough to make one free jump from the first location to the second one, which is also the last one, so the answer is 00.

In the second test case, the only way to move from the first location to the last one is to jump between them, which will cost 44 coins.

In the third test case, you can jump from the first location to the third for 22 coins, and then jump to the fourth location for free, so the answer is 22. It can be shown that this is the optimal way.

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int a[110];
		int f1=0,f2=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==0&&a[i-1]==1&&!f1)
			{
				f1=i;
			}
			else if(a[i]==1&&a[i-1]==0)
			{
				f2=i;
			}
		}
		if(f1)
		{
		//	cout<<f2<<" "<<f1<<endl;
			cout<<f2-f1+1<<endl;
		}
		else
		cout<<0<<endl;
		
	
		
	}
	return 0;
}

{ Game : SA.exe Version: Date : 2025-11-06 Author : Himono This script does blah blah blah } [ENABLE] aobscanmodule(INJECT,x64-msvcrt-ruby310.dll,ERROR: 无法找到独特的 AOB, 代码可靠吗 "48 89 10 48 8B 4D 28") // should be unique alloc(newmem,$1000,INJECT) label(code) label(return) newmem: code: mov [rax],rdx mov rcx,[rbp+28] jmp return INJECT: jmp newmem nop 2 return: registersymbol(INJECT) [DISABLE] INJECT: db 48 89 10 48 8B 4D 28 unregistersymbol(INJECT) dealloc(newmem) { // ORIGINAL CODE - INJECTION POINT: x64-msvcrt-ruby310.rb_locale_charmap_index+9C1 x64-msvcrt-ruby310.rb_locale_charmap_index+9A0: C3 - ret x64-msvcrt-ruby310.rb_locale_charmap_index+9A1: 55 - push rbp x64-msvcrt-ruby310.rb_locale_charmap_index+9A2: 48 89 E5 - mov rbp,rsp x64-msvcrt-ruby310.rb_locale_charmap_index+9A5: 48 83 EC 30 - sub rsp,30 x64-msvcrt-ruby310.rb_locale_charmap_index+9A9: 48 89 4D 10 - mov [rbp+10],rcx x64-msvcrt-ruby310.rb_locale_charmap_index+9AD: 48 89 55 18 - mov [rbp+18],rdx x64-msvcrt-ruby310.rb_locale_charmap_index+9B1: 4C 89 45 20 - mov [rbp+20],r8 x64-msvcrt-ruby310.rb_locale_charmap_index+9B5: 4C 89 4D 28 - mov [rbp+28],r9 x64-msvcrt-ruby310.rb_locale_charmap_index+9B9: 48 8B 45 18 - mov rax,[rbp+18] x64-msvcrt-ruby310.rb_locale_charmap_index+9BD: 48 8B 55 20 - mov rdx,[rbp+20] // ---------- INJECTING HERE ---------- x64-msvcrt-ruby310.rb_locale_charmap_index+9C1: 48 89 10 - mov [rax],rdx // ---------- DONE INJECTING ---------- x64-msvcrt-ruby310.rb_locale_charmap_index+9C4: 48 8B 4D 28 - mov rcx,[rbp+28] x64-msvcrt-ruby310.rb_locale_charmap_index+9C8: 48 8B 55 20 - mov rdx,[rbp+20] x64-msvcrt-ruby310.rb_locale_charmap_index+9CC: 8B 45 30 - mov eax,[rbp+30] x64-msvcrt-ruby310.rb_locale_charmap_index+9CF: 89 44 24 20 - mov [rsp+20],eax x64-msvcrt-ruby310.rb_locale_charmap_index+9D3: 49 89 C9 - mov r9,rcx x64-msvcrt-ruby310.rb_locale_charmap_index+9D6: 49 89 D0 - mov r8,rdx x64-msvcrt-ruby310.rb_locale_charmap_index+9D9: BA 34 00 00 00 - mov edx,00000034 x64-msvcrt-ruby310.rb_locale_charmap_index+9DE: 48 8B 4D 10 - mov rcx,[rbp+10] x64-msvcrt-ruby310.rb_locale_charmap_index+9E2: E8 75 FF FF FF - call x64-msvcrt-ruby310.rb_locale_charmap_index+95C x64-msvcrt-ruby310.rb_locale_charmap_index+9E7: 48 8B 45 10 - mov rax,[rbp+10] }
11-07
D:\Vscode projecct\mod-manager>npm run electron:build > mod-manager@1.0.0 electron:build > electron-builder • electron-builder version=26.0.12 os=10.0.19045 • loaded configuration file=package.json ("build" field) • writing effective config file=dist-electron\builder-effective-config.yaml • executing @electron/rebuild electronVersion=36.5.0 arch=x64 buildFromSource=false appDir=./ • installing native dependencies arch=x64 • completed installing native dependencies • packaging platform=win32 arch=x64 electron=36.5.0 appOutDir=dist-electron\win-unpacked • updating asar integrity executable resource executablePath=dist-electron\win-unpacked\Katerila Mod Manager.exe • building target=portable file=dist-electron\Katerila Mod Manager 1.0.0.exe archs=x64 ⨯ C:\Users\ZHAO\AppData\Local\electron-builder\Cache\nsis\nsis-3.0.4.1\Bin\makensis.exe process failed ERR_ELECTRON_BUILDER_CANNOT_EXECUTE Exit code: 1 Output: Command line defined: "APP_ID=com.example.modmanager" Command line defined: "APP_GUID=e938a568-806b-5b88-a79d-7ea10ce92360" Command line defined: "UNINSTALL_APP_KEY=e938a568-806b-5b88-a79d-7ea10ce92360" Command line defined: "PRODUCT_NAME=Katerila Mod Manager" Command line defined: "PRODUCT_FILENAME=Katerila Mod Manager" Command line defined: "APP_FILENAME=mod-manager" Command line defined: "APP_DESCRIPTION=A mod manager for game modifications" Command line defined: "VERSION=1.0.0" Command line defined: "PROJECT_DIR=D:\Vscode projecct\mod-manager" Command line defined: "BUILD_RESOURCES_DIR=D:\Vscode projecct\mod-manager\build" Command line defined: "APP_PACKAGE_NAME=mod-manager" Command line defined: "APP_64=D:\Vscode projecct\mod-manager\dist-electron\mod-manager-1.0.0-x64.nsis.7z" Command line defined: "APP_64_NAME=mod-manager-1.0.0-x64.nsis.7z" Command line defined: "APP_64_HASH=1B1D801536CF05130BBD682448104A2F7D845F99537C56ED9AD5190B4F85FC4CC3CAC72E26358302451CAE6D77100CA6C0E7A52238A0ECA385E32D8D506E2AF0" Command line def
06-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值