Back

双色球

|

这个其实挺蠢的, 老师又说你hardcode啦.
[cc lang="java" line\_numbers="true"]
public class LotteryQuestion
{
private static int start2generateBalls()
{
return C(33, 6) \* C(16, 1);// 33选6,16选1
}
static int C(int k, int n)
{
int rs = 1;
for (int i = 1; i <= n; i++)
rs = rs \* (k - i + 1) / i;
return rs;
}
static int Bingo(int type)
{
int fenmu;
switch (type)
{
case 1:
fenmu = 1;
break;
case 2:
fenmu = 15;
break;
case 3:
fenmu = 6 \* 27;
break;
case 4:
fenmu = C(6, 5) \* C(27, 1) \* C(15, 1) + C(6, 4) \* C(27, 2);
break;
case 5:
fenmu = C(6, 4) \* C(27, 2) \* C(15, 1) + C(6, 3) \* C(27, 3);
break;
case 6:
fenmu = C(6, 2) \* C(27, 4) + C(6, 1) \* C(27, 5) + C(27, 6);
break;
default:
fenmu = 0;
break;
}
return start2generateBalls() / fenmu;
}
public static void main(String[] args)
{
System.out.println("[一等奖] -> [1/" + Bingo(1) + "]");
System.out.println("[二奖奖] -> [2/" + Bingo(2) + "]");
System.out.println("[三等奖] -> [1/" + Bingo(3) + "]");
System.out.println("[四等奖] -> [1/" + Bingo(4) + "]");
System.out.println("[五等奖] -> [1/" + Bingo(5) + "]");
System.out.println("[末等奖] -> [1/" + Bingo(6) + "]");
}
}[/cc]
> root@11th:/home# java LotteryQuestion
> [一等奖] -> [1/17721088]
> [二奖奖] -> [2/1181405]
> [三等奖] -> [1/109389]
> [四等奖] -> [1/2302]
> [五等奖] -> [1/128]
> [末等奖] -> [1/16]

No comments yet

Leave a comment

About me

I live in Tasmania, an island a little far from the rest of the world and very close to the sea.
Father of two little girls, have two puppies.

Work

Work in IT industry, AI is my working partner.