CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

https://www.codechef.com/DEC17/problems/CPLAY

#include<cstdio>
#include<algorithm>

using namespace std;

char s[21];

int main()
{
    int sumA,sumB;
    while(scanf("%s",s+1)!=EOF)
    {
        sumA=sumB=0;
        int i;
        for(i=1;i<=10;++i)
        {
            if(i&1)
            {
                if(s[i]==‘1‘)
                {
                    sumA++;
                    if(sumA-sumB>(10-i+1)/2) break;
                }
                else
                {
                    if(sumB-sumA>(10-i)/2) break;
                }
            }
            else
            {
                if(s[i]==‘1‘)
                {
                    sumB++;
                    if(sumB-sumA>(10-i)/2) break;
                }
                else
                {
                    if(sumA-sumB>(10-i)/2) break;
                }
            }
        }
        if(i!=11)
        {
            printf(sumA>sumB ? "TEAM-A" : "TEAM-B");
            printf(" %d\n",i);
            continue;
        }
        for(;i<=20;i+=2)
        {
            if(s[i]==‘1‘) sumA++;
            if(s[i+1]==‘1‘) sumB++;
            if(sumA!=sumB) break;
        }
        if(i!=21)
        {
            printf(sumA>sumB ? "TEAM-A" : "TEAM-B");
            printf(" %d\n",i+1);
            continue;
        }
        puts("TIE");
    }
} 

Read problems statements in Mandarin chineseRussian andVietnamese as well.

Chef likes to play football with his friends. They played a number of matches and surprisingly, every match was a tie, so they decided to declare the winner with penalty shoot-out. As they didn‘t know the penalty shoot-out rules, they just decided to take 20 shots alternatively (each team takes 10 shots).

One day, Chef‘s friend Shivam heard about the matches and got confused. Later Shivam went to Chef and his friends and explained the shoot-out rules. Then, they all decided to calculate and once again declare the winner of each match as per the standard football penalty shoot-out rules.

The standard rules are:

  • The teams will take shots alternatively.
  • At first, each team will take five penalty shots.
  • If one team does not have more goals than the other after these five shots, the shoot-out will proceed to sudden death.
  • In between of first 10 kicks, If one team has an advantage over other which can‘t be compensated, then the team with the advantage will be declared winner at that instant i.e. before the completion of 10 kicks.
  • In sudden death, each team will take at most five more shots. Everytime after both teams take a shot, the following rule is used: if one team has scored more goals than the other, that team is the winner.
  • If each team has taken 10 shots and the winner still cannot be decided, the result will be a tie.

The result of the shoot-out for each game is given as a binary string where ‘1‘ represents GOAL and ‘0‘ represents MISS. Chef‘s team always starts first. Keep in mind that the teams alternate when taking the shots — the first character corresponds to the first shot of Chef‘s team, the second character to the first shot of the opposing team, the third character to the second shot of Chef‘s team etc.

As there are many matches to evaluate, Chef and his friends are unable to do so and they require your help. You have to tell them the winner of each match.

If a match ended in a tie, print "TIE". If Chef‘s team won, print "TEAM-A", otherwise print "TEAM-B". Also, if the match didn‘t end in a tie, print the minimum number of kicks required to decide the result, so that they can also know how much times they shot in vain.

Note: Input/Output files are large, use fast reading/writing methods

Input

  • The input consists of several lines.
  • Each line contains the record of the shoot-out for a single match in the form of a binary string where ‘1‘ represents GOAL and ‘0‘ represents MISS, starting from Chef‘s team alternatively.

Output

On each line, print the winner of the corresponding match ("TEAM-A" or "TEAM-B") and the number of shots required to decide the result, separated by a space. If there is no winner, print "TIE" instead.

Constraints

  • each line contains a 20-bit binary string
  • number of matches ≤ 106

Subtasks

Subtask 1 (20 points):

  • the first 10 kicks always result in a tie, i.e. the shoot-out will always go to sudden death
  • number of matches ≤ 103

Subtask 2 (80 points): original constraints

Example

Input:

10100101111011111111
00000000000000000000
01011101110110101111

Output:

TEAM-A 12
TIE
TEAM-B 7

Explanatio

时间: 2024-08-20 07:51:35

CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out的相关文章

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using namespace std; #define N 101 char s[N]; int main() { int T; scanf("%d",&T); int n,m; int OddG,OddR,EvenG,EvenR; int ans; while(T--) { OddG=O

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #include<iostream> using namespace std; #define N 100001 int a[N],b[N]; int sum[N],wh[N][2]; int num1[N],num2[N]; void read(int &x) { x=0; char c=getc

CF&amp;&amp;CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define N 1000001 long long sum[N*2],dp[N]; int num[11]; void read(int &x) { x=0; char c=getchar(); while(!isdi

CF&amp;&amp;CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 然后可以对区间剩余数重排 继续删除下标为等差数列且数值相等的一些数 继续对区间进行重排 直至区间内没有数 问每次操作的最少删除次数 因为每次删除后可以重排 那么完全可以在第一次删除后就把区间相等的数排在一起 这样相等的数的下标就分别构成了公差为1的等差数列 所以问题转化为 设区间[l,r]内数有x

CF&amp;&amp;CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的数都下取整,累积更改的sum 那么选1个小数上取整,就会使sum-1 整数上下取整不会产生影响 所以有1个整数就可以使上取整的小数少1个 所以ans=min(abs(i-sum)) i∈[n-整数个数,n] #include<cmath> #include<cstdio> #inclu

Codechef December Challenge 2014 Chef and Apple Trees 水题

Chef and Apple Trees Chef loves to prepare delicious dishes. This time, Chef has decided to prepare a special dish for you, and needs to gather several apples to do so. Chef has N apple trees in his home garden. Each tree has a certain (non-zero) num

[codechef July Challenge 2017] IPC Trainers

IPCTRAIN: 训练营教练题目描述本次印度编程训练营(Indian Programming Camp,IPC)共请到了 N 名教练.训练营的日程安排有 M 天,每天最多上一节课.第 i 名教练在第 Di 天到达,直到训练营结束才离开.第 i 名教练希望上 Ti 节课.要是少上了课,那么教练会感到扎心,每少上一节,扎心值就会加 Si.作为主办方,你希望最小化所有教练的扎心值之和.输入格式输入的第一行包含一个整数 T,代表测试数据的组数.接下来是 T 组数据.每组数据的第一行包含两个整数 N 和

[codechef July Challenge 2017] Chef and Sign Sequences

CHEFSIGN: 大厨与符号序列题目描述大厨昨天捡到了一个奇怪的字符串 s,这是一个仅包含'<'.'='和'>'三种比较符号的字符串.记字符串长度为 N,大厨想要在字符串的开头.结尾,和每两个字符之间插入一个正整数,共N + 1 个数.大厨希望插入数字之后,这些比较符号所表达的含义是正确的.举个例子,如果在'<'前后分别插入 a 和 b,那么应当有 a < b.对于'='和'>'也是类似的.大厨可以在 [1, P] 中任意选择数字插入,同一个数也可以被插入到多个位置.请你帮

[codechef July Challenge 2017] Calculator

CALC: 计算器题目描述大厨有一个计算器,计算器上有两个屏幕和两个按钮.初始时每个屏幕上显示的都是 0.每按一次第一个按钮,就会让第一个屏幕上显示的数字加 1,同时消耗 1 单位的能量.每按一次第二个按钮,会让第二个屏幕上显示的数字加上第一个屏幕上显示的数字,同时消耗 B 单位的能量.初始时,计算器有 N 单位的能量.大厨想知道在能量限制下,第二个屏幕上最大可以出现的数字是多少?输入格式输入的第一行包含一个整数 T,代表测试数据的组数.接下来是 T 组数据.每组数据仅有一行,包含两个整数 N