33,008
社区成员
发帖
与我相关
我的任务
分享
public static long getRen9Numbers(boolean[] winChecked,
boolean[] tieChecked,boolean[] lossChecked) throws Exception {
TreeSet<Integer> first=new TreeSet<>();
TreeSet<Integer> second=new TreeSet<>();
TreeSet<Integer> three=new TreeSet<>();
for(int i=0;i<winChecked.length;i++){
if(winChecked[i]){
first.add(i);
}
}
for(int i=0;i<tieChecked.length;i++){
if(tieChecked[i]){
if(first.contains(i)){
second.add(i);
}else{
first.add(i);
}
}
}
for(int i=0;i<lossChecked.length;i++){
if(lossChecked[i]){
if(first.contains(i)){
if(second.contains(i)){
three.add(i);
}else{
second.add(i);
}
}else{
first.add(i);
}
}
}
long num=0;
if(first.size()<9){
num = 0;
}else{
if(second.size()==0){
num= combineNum(first.size(),9).intValue();
}else{
if(three.size()==0){
for(int i=0;i<=second.size();i++){
num=num+combineNum(second.size(),i).longValue()*
combineNum(first.size()-i,9-i).longValue();
}
}else{
for(int i=0;i<=three.size();i++){
long count1=0;
for(int j=0;j<=second.size()-i;j++){
count1=count1+combineNum(second.size()-i,j).longValue()*
combineNum(first.size()-(j+i),9-(j+i)).longValue();
}
num=num+combineNum(three.size(),i).longValue()*count1;
}
}
}
}
return num;
}
/*
* 任选9场 根据选号结果计算选号注数
* */
public static int getRen9Numbers(boolean[] winChecked,boolean[] tieChecked,boolean[] lossChecked)
throws Exception{
TreeSet<Integer> first=new TreeSet<>();
TreeSet<Integer> second=new TreeSet<>();
TreeSet<Integer> three=new TreeSet<>();
for(int i=0;i<winChecked.length;i++){
if(winChecked[i]){
first.add(i);
}
}
for(int i=0;i<tieChecked.length;i++){
if(tieChecked[i]){
if(first.contains(i)){
second.add(i);
}else{
first.add(i);
}
}
}
for(int i=0;i<lossChecked.length;i++){
if(lossChecked[i]){
if(first.contains(i)){
if(second.contains(i)){
three.add(i);
}else{
second.add(i);
}
}else{
first.add(i);
}
}
}
int num=0;
if(first.size()<9){
num = 0;
}else{
if(second.size()==0){
num= combineNum(first.size(),9).intValue();
}else{
if(three.size()==0){
num=combineNum(first.size(),9).intValue();
for(int i=1;i<=second.size();i++){
num=num+combineNum(first.size()-i,9-i).intValue()
*combineNum(second.size(),second.size()-i).intValue();
}
}else{
if(three.size()==second.size()){
if(first.size()==9){
num=(int)Math.pow(3,three.size());
}else{
num=combineNum(first.size(),9).intValue();
for(int i=1;i<=second.size();i++){
if(i==1){
num=num+combineNum(first.size()-i,9-i).intValue()
*combineNum(2*second.size(),i).intValue();
}else{
num=num+combineNum(first.size()-i,9-i).intValue()
*(combineNum(2*second.size(),i).intValue()-
second.size()*combineNum(2*second.size()-2*(i-1),i-1).intValue());
}
}
}
}else {
if(first.size()==9){
num= (int)(Math.pow(3,three.size())*Math.pow(2,second.size()-three.size())
*combineNum(first.size(),9).intValue());
}else{
num=-1;
}
}
}
}
}
return num;
}
在再附上这几天的代码
最后一步还是没搞定