After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad.

The crossroads are represented as a string s of length n, where si=A, if there is a bus station at i-th crossroad, and si=B, if there is a tram station at i-th crossroad. Currently Petya is at the first crossroad (which corresponds to s1) and his goal is to get to the last crossroad (which corresponds to sn).

If for two crossroads i and j for all crossroads i,i+1,…,j−1 there is a bus station, one can pay a roubles for the bus ticket, and go from i-th crossroad to the j-th crossroad by the bus (it is not necessary to have a bus station at the j-th crossroad). Formally, paying a roubles Petya can go from i to j if st=A for all i≤t<j.

If for two crossroads i and j for all crossroads i,i+1,…,j−1 there is a tram station, one can pay b roubles for the tram ticket, and go from i-th crossroad to the j-th crossroad by the tram (it is not necessary to have a tram station at the j-th crossroad). Formally, paying b roubles Petya can go from i to j if st=B for all i≤t<j.

For example, if s=“AABBBAB”, a=4 and b=3 then Petya needs:

buy one bus ticket to get from 1 to 3,

buy one tram ticket to get from 3 to 6,

buy one bus ticket to get from 6 to 7.

Thus, in total he needs to spend 4+3+4=11 roubles. Please note that the type of the stop at the last crossroad (i.e. the character sn) does not affect the final expense.

Now Petya is at the first crossroad, and he wants to get to the n-th crossroad. After the party he has left with p roubles. He’s decided to go to some station on foot, and then go to home using only public transport.

Help him to choose the closest crossroad i to go on foot the first, so he has enough money to get from the i-th crossroad to the n-th, using only tram and bus tickets.

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1≤t≤104).

The first line of each test case consists of three integers a,b,p (1≤a,b,p≤105) — the cost of bus ticket, the cost of tram ticket and the amount of money Petya has.

The second line of each test case consists of one string s, where si=A, if there is a bus station at i-th crossroad, and si=B, if there is a tram station at i-th crossroad (2≤|s|≤105).

It is guaranteed, that the sum of the length of strings s by all test cases in one test doesn’t exceed 105.

Output

For each test case print one number — the minimal index i of a crossroad Petya should go on foot. The rest of the path (i.e. from i to n he should use public transport).

这个题倒着从后向前模拟,模拟题傻逼

#include <bits/stdc++.h>
using namespace std;
char s[100000];
long long a, b, p,t;
long long solve()
{
int l = strlen(s + 1);
int cnt = 0;
int u = 0;
for (int i = l; i >= 2; i--)
{
if (u == 0)
{
if (s[i - 1] == 'A')
{
if (p >= a)
{
p -= a;
u = 1;
cnt++;
}
else
break;
}
if (s[i - 1] == 'B')
{
if (p >= b)
{
p -= b;
u = 2;
cnt++;
}
else
break;
}
}
else if (u == 1)
{
if (s[i - 1] == 'B')
{
if (p >= b)
{
p -= b;
u = 2;
cnt++;
}
else
break;
}
else
cnt++;
}
else if (u == 2)
{
if (s[i - 1] == 'A')
{
if (p >= a)
{
p -= a;
u = 1;
cnt++;
}
else
break;
}
else
cnt++;
}
}
return l - cnt;
}
int main()
{
cin >> t;
while (t--)
{ cin >> a >> b >> p;
scanf("%s", s + 1);
cout<<solve()<<endl;
}
}

Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) B. Homecoming的更多相关文章

  1. Codeforces Round 623(Div. 2,based on VK Cup 2019-2020 - Elimination Round,Engine)D. Recommendations

    VK news recommendation system daily selects interesting publications of one of n disjoint categories ...

  2. Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)

    #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp( ...

  3. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

    A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...

  4. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) C. Restoring

    C. Restoring Permutation time limit per test1 second memory limit per test256 megabytes inputstandar ...

  5. Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) A Dead Pixel

    讨论坏点的左右上下的矩形大小. #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> ...

  6. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】

    比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...

  7. Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)

    题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...

  8. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) D. Extreme Subtraction (贪心)

    题意:有一个长度为\(n\)的序列,可以任意取\(k(1\le k\le n)\),对序列前\(k\)项或者后\(k\)减\(1\),可以进行任意次操作,问是否可以使所有元素都变成\(0\). 题解: ...

  9. Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)

    题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...

随机推荐

  1. webpack4.0(01.基础配置和初识)

    1.什么是webpack? 2.webpack可以做什莫? 代码转换.文件优化.代码分割.模块合并.自动刷新.代码校验.自动发布 3.我们要学习webpack的什么? 4.使用webpack 1.首先 ...

  2. 从JDK源码学习HashSet和HashTable

    HashSet Java中的集合(Collection)有三类,一类是List,一类是Queue,再有一类就是Set. 前两个集合内的元素是有序的,元素可以重复:最后一个集合内的元素无序,但元素不可重 ...

  3. 多角度让你彻底明白yield语法糖的用法和原理及在C#函数式编程中的作用

    如果大家读过dapper源码,你会发现这内部有很多方法都用到了yield关键词,那yield到底是用来干嘛的,能不能拿掉,拿掉与不拿掉有多大的差别,首先上一段dapper中精简后的Query方法,先让 ...

  4. Java Random 随机数

    package myrandom; import java.util.Random; /* * Random:用于产生随机数 * * 使用步骤: * A:导包 * import java.util.R ...

  5. "格式化的文本"组件:<span> —— 快应用原生组件

     `<template> <div class="container"> <text><span class="success ...

  6. mysql报错: unknown variable 'sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'

    在修改mysql默认字符集的时候: 1. 需要拷贝/usr/share/mysql下的my-huge.cnf 或者my-small.cnf到 /etc/my.cnf,但是官网说:从5.7.18开始不在 ...

  7. AJ学IOS 之微博项目实战(5)微博自定义搜索框searchBar

    AJ分享,必须精品 一:效果 用UITextField简单定义一个搜索框 二:调用: 调用的代码,很简单,直接init就可以,以后加功能自己添加就行了. - (void)viewDidLoad { [ ...

  8. JMF 下载安装与测试 测试成功

    本来就是想在自己写的java里面加入实习的摄像头监控,然后个各种百度了一下,就用JMF来弄了,不过这个东西貌似比较旧,网上的资料虽然说有,但是也不是太多,并且遇到的一下问题也不能解决,总之经过了一天的 ...

  9. ASE课程总结 by 冯晓云

    开始的开始,采访往届ASE班的blog:http://www.cnblogs.com/legs/p/4894362.html 和北航软工M1检查:http://www.cnblogs.com/legs ...

  10. A - Chat Group Gym-101775A

    题目连接:https://codeforces.com/gym/101775/problem/A 题解:就是累加组合数 但是直接由K累加到N肯定会TLE ,所以我们不妨判断不能组成group的情况,即 ...