zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",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

  • 相关阅读:
    成为JAVA(高级)工程师
    JVM的内存区域划分以及垃圾回收机制
    XML
    String.valueOf
    JAVA书籍(2)
    JAVA书籍(1)
    深入JAVA线程池
    FileWriter与BufferedWriter
    获取下拉框的文本或值
    删除字符串最后一个字符的几种方法
  • 原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/8059965.html
Copyright © 2011-2022 走看看