`
snake_hand
  • 浏览: 575733 次
社区版块
存档分类
最新评论

5威威猫系列故事——篮球梦

 
阅读更多
 

Problem Description

威威猫十分迷恋篮球比赛,是忠实的NBA球迷,他常常幻想自己那肥硕的身躯也能飞起扣篮。另外,他对篮球教练工作也情有独钟,特别是对比赛的战术,投篮选择方面也是很有研究,下面就是威威猫研究过的一个问题:

一场NBA篮球比赛总共48分钟,假如我们现在已经知道当前比分 A:B,A代表我方的比分,B代表对方的比分,现在比赛还剩下t秒时间。我们简单的认为双方各自进攻一次的时间皆固定为15秒(不到15秒则进攻不得分),且为交替进攻,即我方进攻一次,接着对方进攻,依次循环。


进攻有三种选择方式:(这里不考虑命中率)

1、造犯规,(假设都两罚一中)得1分;

2、中距离投篮得2分;

3、三分球得3分。


为了简化问题,假设在对方回合,由于我方防守比较好,只让对手得1分,且为固定,即对方的进攻回合就为每回合得1分。现在比赛进入最后关头,接下来第一个回合是我方进攻,现在威威猫想要知道教练有多少种不同的选择能使我方可能赢得比赛(可能的意思就是不考虑命中率的情况)。

Input

输入有多组数据(不超过250组);

每组数据包含3个整数A,B和t,其中A和B 表示当前的比分(0 <= A, B <= 200),t表示还剩多少时间(单位秒 0 <= t <= 600)。


Output

请输出可行的方案数,每组数据输出占一行。


Sample Input

88 90 50

Sample Output

6

Hint

样例解析:
当前比分是88:90,还剩50秒则对方还最多有一次进攻机会(最后5秒进攻不成功),我方有两次,对方的最终得分将是91,我方至少在两回合中拿到4分才能胜利,所以所有方案数是6种,即:

第一球第二球
1       3
2       2
2       3
3       1
3       2
3       3

 

Java代码,递归实现:

package test;

public class HackthonMain {

    public HackthonMain(){}

    public static void main(String[] args) throws Exception {
        CalcWinSolution(88,90,50);
    }
    
    private static int count = 0;     //A赢B的方案数量
    private static Boolean shortOneRound = false;    //B比A是否少一轮
    
    public static void CalcWinSolution(int sa, int sb, int remain_t) throws Exception{
        final int round_t = 30;    //一回合的时间(s)

        int my_round = (remain_t/round_t);    //A方所剩余的回合数
        if(((remain_t%round_t)-15)>=0) {
            my_round++;
            shortOneRound = true;
        }
        
        int diffscore = sa-sb;    //A比B多的分数,
        if(diffscore>=0){
            System.out.println(Math.pow(3, my_round));
        }
        else if((diffscore+(my_round*3))<0){
            System.out.println(0);
        }
        else{
            //diffscore<0
            CalcWinTimes(diffscore,my_round);
            System.out.println(count);
        }
    }

    
    public static void CalcWinTimes(int diffscore,int round) throws Exception{
        if(round==0){    //不剩余任何回合数
            if(shortOneRound) diffscore++;
            
            if(diffscore>0)    count++;
            
            return;
        }
        else if(round<0){
            throw new Exception("round < 0");
        }
        else{
            if((round-1)>=0){
                CalcWinTimes(diffscore+3-1,round-1);
                CalcWinTimes(diffscore+2-1,round-1);
                CalcWinTimes(diffscore+1-1,round-1);
            }
        }
    }
}
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics