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. angularJS1笔记-(17)-ng-bind-html指令

    angular不推荐大家在绑定数据的时候绑定html,但是如果你非要这么干也并不是不可以的.举个例子: <!DOCTYPE html> <html lang="en&quo ...

  2. HTTPS链式编程——AFNetworking 3.0

    1. HTTPS 证书认证(导入相关证书) #pragma mark - https认证 - (AFSecurityPolicy*)customSecurityPolicy { // 先导入证书 NS ...

  3. 发布.NET Core到IIS

    目录: 支持操作系统 IIS配置 安装.NET Core Windows Server Hosting 部署应用程序 在IIS配置网站 创建一个数据保护注册表项 常见的错误 额外的资源 支持操作系统 ...

  4. 初识nginx——配置解析篇

    一.nginx的介绍 nginx是由俄罗斯人开发的一款高性能的http和反向代理服务器,也可以用来作为邮件代理.相比较于其他的服务器,具有占用内存少,稳定性高等优势 二.nginx的配置 nginx的 ...

  5. vue 如何使用scss (转载)

    创建一个基于 webpack 模板的新项目 全局安装 vue-cli $ npm install --global vue-cli 创建一个基于 webpack 模板的新项目 $ vue init w ...

  6. php SPL标准库iterator和ArrayAccess的学习

    最近在补充学习php基础的时候看到了spl的介绍,学习了一下iterator和arrayAccess的使用,iterator主要是对象的迭代,一般可以用在容器里面,或者工厂模式里面,最常见的应用场景就 ...

  7. 【Web Shell】- 技术剖析中国菜刀 – Part I

    这里的中国菜刀不是指切菜做饭的工具,而是中国安全圈内使用非常广泛的一款Webshell管理工具,想买菜刀请出门左拐东门菜市场王铁匠处.中国菜刀用途十分广泛,支持多种语言,小巧实用,据说是一位中国军人退 ...

  8. SpringBoot(四)_Spring Data JPA的使用

    JPA 绝对是简化数据库操作的一大利器. 概念 首先了解 JPA 是什么? JPA(Java Persistence API)是 Sun 官方提出的 Java 持久化规范.它为 Java 开发人员提供 ...

  9. STM32CubeMX介绍、下载与安装

    一.简介 STM32CubeMX是一个配置STM32代码的工具,它把很多东西封装的比较好,硬件抽象层.中间层.示例代码等.现在ST公司升级和维护的库主要就是STM32CubeMX的HAL库和标准外设库 ...

  10. centOS基本操作和命令(更新)

    1.文字输入和图形界面切换 CTRL+ALT+(F1~F6)为切换至文字输入,分别对应六个不同输入界面,可用以不同账号:CTRL+ALT+F7为切换至图形界面 2.修改时区 date -R date ...