CODEFORCES Day 16

题目:

C. Penalty

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Consider a simplified penalty phase at the end of a football match.

A penalty phase consists of at most 1010 kicks, the first team takes the first kick, the second team takes the second kick, then the first team takes the third kick, and so on. The team that scores more goals wins; if both teams score the same number of goals, the game results in a tie (note that it goes against the usual football rules). The penalty phase is stopped if one team has scored more goals than the other team could reach with all of its remaining kicks. For example, if after the 77-th kick the first team has scored 11 goal, and the second team has scored 33 goals, the penalty phase ends — the first team cannot reach 33 goals.

You know which player will be taking each kick, so you have your predictions for each of the 1010 kicks. These predictions are represented by a string 𝑠s consisting of 1010 characters. Each character can either be 1, 0, or ?. This string represents your predictions in the following way:

  • if 𝑠𝑖si is 1, then the 𝑖i-th kick will definitely score a goal; 
  • if 𝑠𝑖si is 0, then the 𝑖i-th kick definitely won't score a goal; 
  • if 𝑠𝑖si is ?, then the 𝑖i-th kick could go either way. 

Based on your predictions, you have to calculate the minimum possible number of kicks there can be in the penalty phase (that means, the earliest moment when the penalty phase is stopped, considering all possible ways it could go). Note that the referee doesn't take into account any predictions when deciding to stop the penalty phase — you may know that some kick will/won't be scored, but the referee doesn't.

Input

The first line contains one integer 𝑡t (1≤𝑡≤10001≤t≤1000) — the number of test cases.

Each test case is represented by one line containing the string 𝑠s, consisting of exactly 1010 characters. Each character is either 1, 0, or ?.

Output

For each test case, print one integer — the minimum possible number of kicks in the penalty phase.

题目意思:有两只队伍比罚球,两只队伍轮流罚球,各自最多罚五次,小明是预言家,提前知道罚球的结果,并且把这结果告诉了你,那么这两个队伍最少罚几次球呢?(1为进球,0为没进球,?为随意)

思路:当一只队伍的进球数大于另一只队伍的进球数+剩下的罚球机会,或者打满10局那么则可以终止比赛,记录1和0的数量,?则分俩种情况,A队的?全进,B队的?全不进,以及A队的?全不进,B队的问号全进,然后比较哪种情况次数更少

#include<iostream>
#include<string>
typedef long long ll;
using namespace std;
int main() {
    int T;
    cin >> T;
    while (T--)
    {
        int a=0,b=0,ans=10;
        string s;
        cin>>s;
        s=' '+s;
        for (int i=1; i<=10; i++) {
            if (i%2==0) {
                if (s[i]=='1') {
                    b++;
                }
            }
            else {
                if(s[i]=='1'||s[i]=='?')a++;}
            if (a>b+(10-i+1)/2) {
                if (i<ans) {
                    ans=i;
                }
                break;
            }
        }
        a=0;
        b=0;
        for (int i=1; i<=10; i++) {
            if (i%2==0) {
                if (s[i]=='1'||s[i]=='?') {
                    b++;
                }
            }
            else{
                if(s[i]=='1')a++;}
            if (b>a+(10-i)/2) {
                if (i<ans) {
                    ans=i;
                }
                break;
            }
        }
        cout<<ans<<endl;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值