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

#include<cstdio>
#include<algorithm> using namespace std; char s[]; int main()
{
int sumA,sumB;
while(scanf("%s",s+)!=EOF)
{
sumA=sumB=;
int i;
for(i=;i<=;++i)
{
if(i&)
{
if(s[i]=='')
{
sumA++;
if(sumA-sumB>(-i+)/) break;
}
else
{
if(sumB-sumA>(-i)/) break;
}
}
else
{
if(s[i]=='')
{
sumB++;
if(sumB-sumA>(-i)/) break;
}
else
{
if(sumA-sumB>(-i)/) break;
}
}
}
if(i!=)
{
printf(sumA>sumB ? "TEAM-A" : "TEAM-B");
printf(" %d\n",i);
continue;
}
for(;i<=;i+=)
{
if(s[i]=='') sumA++;
if(s[i+]=='') sumB++;
if(sumA!=sumB) break;
}
if(i!=)
{
printf(sumA>sumB ? "TEAM-A" : "TEAM-B");
printf(" %d\n",i+);
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

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

  1. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

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

    https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...

  3. CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

    https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...

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

    https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...

  5. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  6. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

  7. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

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

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  9. CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle

    http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...

随机推荐

  1. 软工实践-Beta 冲刺 (7/7)

    队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...

  2. Reaction to 构造之法 of Software Engineering From The First Chapter toThe Fifth Chapter(补充版)

    几个星期前,我阅读过一篇文章,一位老师教导自己的学生要积极地去阅读文学文献,其中,我很欣赏他的一句话:“Just think of liturature as if you're reading a ...

  3. BETA-2

    前言 我们居然又冲刺了·二 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 过去两天完成了哪些任务 了解OpenCV下的视频参数及其调用方法 初步编码 接下来的计划 文档工作 速 ...

  4. Java Head First & 多态

    package com.cwcec.tag; class Fruit { } class Apple extends Fruit{} class Animal { public Fruit eat(F ...

  5. vue-cli配置axios

    1. npm install axios --save 2. npm install @type/axios --save-dev(使用ts编写的需要此声明文件,升级的axios好像不需要了,已经自带 ...

  6. poj 2299 Ultra-QuickSort(树状数组求逆序数)

    链接:http://poj.org/problem?id=2299 题意:给出n个数,求将这n个数从小到大排序,求使用快排的需要交换的次数. 分析:由快排的性质很容易发现,只需要求每个数的逆序数累加起 ...

  7. 一个java高级工程师的进阶

    宏观方面 一. JAVA.要想成为JAVA(高级)工程师肯定要学习JAVA.一般的程序员或许只需知道一些JAVA的语法结构就可以应付了.但要成为JAVA(高级) 工程师,您要对JAVA做比较深入的研究 ...

  8. Python动态规划求解最长递增子序列(LIS)

    原始代码错误,移步博客查看O(N^2)及优化的O(N*logN)的实现:每天一道编程题--最长递增子序列

  9. AtCoder Grand Contest 029 翻车记

    A:对于每个B,会和其右边的每个W交换一次. #include<iostream> #include<cstdio> #include<cmath> #includ ...

  10. MT【145】不变的平面角

    (2018,4月学考数学选择最后一题)如图,设矩形$ABCD$所在平面与梯形$ACEF$所在平面相交于$AC$. 若$AB=1,BC=\sqrt{3},AF=EF=EC=1,$则下面二面角的平面角为定 ...