Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine) B. Homecoming
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的更多相关文章
- 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 ...
- 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( ...
- Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)
A. Dead Pixel(思路) 思路 题意:给我们一个m*n的表格,又给了我们表格中的一个点a,其坐标为(x, y),问在这个表格中选择一个不包括改点a的最大面积的矩形,输出这个最大面积 分析:很 ...
- 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 ...
- 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 >> ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)【ABCDF】
比赛链接:https://codeforces.com/contest/1443 A. Kids Seating 题意 构造一个大小为 \(n\) 的数组使得任意两个数既不互质也不相互整除,要求所有数 ...
- Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final) B. Identify the Operations (模拟,双向链表)
题意:给你一组不重复的序列\(a\),每次可以选择一个数删除它左边或右边的一个数,并将选择的数append到数组\(b\)中,现在给你数组\(b\),问有多少种方案数得到\(b\). 题解:我们可以记 ...
- 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\). 题解: ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) C. The Delivery Dilemma (贪心,结构体排序)
题意:你要买\(n\)份午饭,你可以选择自己去买,或者叫外卖,每份午饭\(i\)自己去买需要消耗时间\(b_i\),叫外卖需要\(a_i\),外卖可以同时送,自己只能买完一份后回家再去买下一份,问最少 ...
随机推荐
- django_rest_framework视图传递参数给序列化器
django_rest_framework视图传递参数给序列化器 视图中默认可以将request.data传递给序列化器,但request.data是不可更改的对象,但又想将额外的参数传递给序列化器 ...
- MTK Android 读取SIM卡参数,获取sim卡运营商信息
android 获取sim卡运营商信息(转) TelephonyManager tm = (TelephonyManager)Context.getSystemService(Context.TE ...
- Linux网络安全篇,FTP服务器的架设
一.FTP简介 FTP基于TCP协议.而且FTP服务器使用了命令通道和数据流通道两个连接.两个连接都会分别进行三次握手.在命令通道中客户端会随机取一个大于1024的端口与FTP服务器的21端口建立连接 ...
- 多数据源系统接入mybatis-plus, 实现动态数据源、动态事务。
目录: 实现思想 导入依赖.配置说明 代码实现 问题总结 一.实现思想 接手一个旧系统,SpringBoot 使用的是纯粹的 mybatis ,既没有使用规范的代码生成器,也没有使用 JPA 或者 m ...
- 【python实现卷积神经网络】Dropout层实现
代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...
- centos7 安装php7遇到的问题
环境中安装过php 5.4,觉得版本太低了,因此删除旧版本安装了新版本 1. 安装epel-release 通过命令: rpm -ivh http://dl.fedoraproject.org/pub ...
- G. 蚂蚁的镜像串
单点时限: 1.0 sec 内存限制: 512 MB 一只聪明的蚂蚁在学习了回文串之后,一直觉得回文串不够优美,所以它决定自己定义一种新的字符串——镜像串 所谓镜像串,就是对一个字符串进行一整个完全的 ...
- python做个谷歌内核浏览器
源码: import sys,os os.chdir(os.path.dirname(os.path.abspath(__file__))) from PyQt5.QtGui import * fro ...
- 远程登录redis
没想到吧,我居然已经摸到了redis. 远程登录redis redis-cli -h 127.0.0.1 -p 6379 ip地址和端口记得换成自己的
- lua使用笔记1:Linux 中安装lua
1.lua安装 1)http://www.lua.org/download.html为下载页面 linux中运行 wget http://www.lua.org/ftp/lua-5.2.3.tar.g ...