C. Penalty(CodeForces div.1 +div.2 )

You are given two strings s and t, both consisting of lowercase English letters. You are going to type the string s character by character, from the first character to the last one.

When typing a character, instead of pressing the button corresponding to it, you can press the “Backspace” button. It deletes the last character you have typed among those that aren’t deleted yet (or does nothing if there are no characters in the current string). For example, if s is “abcbd” and you press Backspace instead of typing the first and the fourth characters, you will get the string “bd” (the first press of Backspace deletes no character, and the second press deletes the character ‘c’). Another example, if s is “abcaa” and you press Backspace instead of the last two letters, then the resulting text is “a”.

Your task is to determine whether you can obtain the string t, if you type the string s and press “Backspace” instead of typing several (maybe zero) characters of s.

Input
The first line contains a single integer q (1≤q≤105) — the number of test cases.

The first line of each test case contains the string s (1≤|s|≤105). Each character of s is a lowercase English letter.

The second line of each test case contains the string t (1≤|t|≤105). Each character of t is a lowercase English letter.

It is guaranteed that the total number of characters in the strings over all test cases does not exceed 2⋅105.

Output
For each test case, print “YES” if you can obtain the string t by typing the string s and replacing some characters with presses of “Backspace” button, or “NO” if you cannot.

You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

Example
inputCopy
4
ababa
ba
ababa
bb
aaa
aaaa
aababa
ababa
outputCopy
YES
NO
NO
YES
Note
Consider the example test from the statement.

In order to obtain “ba” from “ababa”, you may press Backspace instead of typing the first and the fourth characters.

There’s no way to obtain “bb” while typing “ababa”.

There’s no way to obtain “aaaa” while typing “aaa”.

In order to obtain “ababa” while typing “aababa”, you have to press Backspace instead of typing the first character, then type all the remaining characters.

题意:

踢10次球,a踢第1次、b踢第2次、a踢第3次… …b踢第10次。问裁判最少可以在第几次踢球后,判断比赛结束。
每次踢球为以下3种情况之一:1 得分,0 不得分,? 得与不得分都有可能。

解题:

我用a[0]表示a当前所得分数(a踢出 1 的次数),a[1]表示a当前踢出 ? 的次数,aa表示a还能踢几次;b与b[0]、b[1]、bb的关系同理。

代码如下:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string.h>
#include <string>
#include <queue>
#include <vector>
#include <utility>//pair
#include <cmath>
#include <limits.h>//INT_MAX  INT_MIN
#include <cstring>
typedef long long ll;
using namespace std;
const int N = 1e5+10;
//10场足球赛
char c[20];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%s",c);
        int a[2]={0},b[2]={0};
        bool flag = false;

        for(int i=0;i<10;i++){
            if(i&1){//Ææ
                if(c[i]=='1') b[0]++;
                else if(c[i]=='?') b[1]++;
            }else{
                if(c[i]=='1') a[0]++;
                else if(c[i]=='?') a[1]++;
            }
            int aa=0,bb=0,x=9-i;
            if(i&1){
                aa=x>>1;
                bb=x>>1;
            }
            else{
                aa=x>>1;
                bb=x+1 >>1;
            }
            if(a[0]+a[1]>b[0]+b[1]){//
                if(a[0]+a[1]>b[0]+bb||b[0]+b[1]>a[0]+aa){
                    printf("%d\n",i+1);
                    flag = true;
                    break;
                }
            }else if(b[0]+b[1]>a[0]+a[1]){
                if(b[0]+b[1]>a[0]+aa||a[0]+a[1]>b[0]+bb){
                    printf("%d\n",i+1);
                    flag = true;
                    break;
                }
            }else{
                if(a[0]+a[1]>b[0]+bb||b[0]+b[1]>a[0]+aa){
                    printf("%d\n",i+1);
                    flag = true;
                    break;
                }
            }
        }
        if(!flag) printf("10\n");
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值