码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-12-19 00:52:09      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:mes   UI   origin   foo   otherwise   with   www.   decided   about   

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

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

标签:mes   UI   origin   foo   otherwise   with   www.   decided   about   

原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/8059965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!