Language: C++

#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<P,P>P2;
#define F first
#define S second
int a[4][4],kati[4],goal[4],goaled[4],gdiff[4],id;
string s[5];
void Perse(){
	memset(a,0,sizeof(a));
	a[0][1]=s[1][11]-'0';
	a[0][2]=s[1][16]-'0';
	a[0][3]=s[1][21]-'0';
	a[1][0]=s[1][13]-'0';
	a[1][2]=s[2][16]-'0';
	a[1][3]=s[2][21]-'0';
	a[2][0]=s[1][18]-'0';
	a[2][1]=s[2][18]-'0';
	a[2][3]=s[3][21]-'0';
	a[3][0]=s[1][23]-'0';
	a[3][1]=s[2][23]-'0';
	a[3][2]=s[3][23]-'0';
	r(i,5)if(s[i][0]=='*')id=i-1;
}
vector<P>use;
void FILL(vector<char> v){
	int c=0;
	if(s[1][11]=='_')s[1][11]=v[c++],use.push_back(P(1,11));
	if(s[1][16]=='_')s[1][16]=v[c++],use.push_back(P(1,16));
	if(s[1][21]=='_')s[1][21]=v[c++],use.push_back(P(1,21));
	if(s[1][13]=='_')s[1][13]=v[c++],use.push_back(P(1,13));
	if(s[2][16]=='_')s[2][16]=v[c++],use.push_back(P(2,16));
	if(s[2][21]=='_')s[2][21]=v[c++],use.push_back(P(2,21));
	if(s[1][18]=='_')s[1][18]=v[c++],use.push_back(P(1,18));
	if(s[2][18]=='_')s[2][18]=v[c++],use.push_back(P(2,18));
	if(s[3][21]=='_')s[3][21]=v[c++],use.push_back(P(3,21));
	if(s[1][23]=='_')s[1][23]=v[c++],use.push_back(P(1,23));
	if(s[2][23]=='_')s[2][23]=v[c++],use.push_back(P(2,23));
	if(s[3][23]=='_')s[3][23]=v[c++],use.push_back(P(3,23));
}

void calc(vector<int> v){
	memset(kati,0,sizeof(kati));
	memset(goal,0,sizeof(goal));
	memset(gdiff,0,sizeof(gdiff));
	memset(goaled,0,sizeof(goaled));
	int c[4]={};
	r(i,v.size())c[v[i]]=1;
	r(i,4)if(c[i]){
		r(j,4)if(c[j])if(i!=j){
			if(a[i][j]>a[j][i])kati[i]+=3;
			else if(a[i][j]==a[j][i])kati[i]+=1;
			goal[i]+=a[i][j];
			goaled[i]+=a[j][i];
		}
		gdiff[i]=goal[i]-goaled[i];
	}
}

void END(){
	exit(0);
}

double get_score(){
	Perse();
	vector<int>v;
	int ue=0;
	r(i,4)v.push_back(i);
	int CC=10;
	while(CC--){
		calc(v);
		vector<P2>sco;
		r(i,v.size()){
			sco.push_back(P2(P(kati[v[i]],gdiff[v[i]]),P(goal[v[i]],v[i])));
		}
		sort(sco.begin(),sco.end(),greater<P2>());
		int cnt=0;
		vector<int>vip[4];
		vip[0].push_back(sco[0].S.S);
		r(i,sco.size()-1){
			if(sco[i].F.F==sco[i+1].F.F&&
				sco[i].F.S==sco[i+1].F.S&&
					sco[i].S.F==sco[i+1].S.F){
						vip[cnt].push_back(sco[i+1].S.S);
					}
			else{
				vip[++cnt].push_back(sco[i+1].S.S);
			}
		}
		v.clear();
		r(i,4){
			r(j,vip[i].size()){
				if(vip[i][j]==id){
					if(i==0&&vip[i].size()==1){
						if(ue<=1)return 1;
						else return 0;
					}
					r(k,vip[i].size()){
						v.push_back(vip[i][k]);
					}
					goto L;
				}
			}
			ue+=vip[i].size();
		}
		L:;
	}
	return (2.0-ue)/v.size();
}
double kai[10];
int main(){
	int test;
	cin>>test;
	kai[0]=kai[1]=1;
	for(int i=2;i<10;i++) kai[i]=kai[i-1]*i;
	while(test--){
		double ans=0;
		r(i,5)cin>>s[i];
		r(i,9)r(j,9)r(k,9)r(l,9){
			double d1=pro[i];
			double d2=pro[j];
			double d3=pro[k];
			double d4=pro[l];
			double d1=(kai[8]/(kai[i]*kai[8-i]))*pow(0.25,i)*pow(0.75,8-i);
			double d2=(kai[8]/(kai[j]*kai[8-j]))*pow(0.25,j)*pow(0.75,8-j);
			double d3=(kai[8]/(kai[k]*kai[8-k]))*pow(0.25,k)*pow(0.75,8-k);
			double d4=(kai[8]/(kai[l]*kai[8-l]))*pow(0.25,l)*pow(0.75,8-l);
			vector<char>v;
			v.push_back(char(i+'0'));
			v.push_back(char(j+'0'));
			v.push_back(char(k+'0'));
			v.push_back(char(l+'0'));
			FILL(v);
			ans+=d1*d2*d3*d4*get_score();
			r(m,4){
				s[use[m].F][use[m].S]='_';
			}
			use.clear();
		}
		printf("%.9f\n",ans);
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:121:35: error: 'pro' was not declared in this scope
  121 |                         double d1=pro[i];
      |                                   ^~~
a.cc:125:32: error: redeclaration of 'double d1'
  125 |                         double d1=(kai[8]/(kai[i]*kai[8-i]))*pow(0.25,i)*pow(0.75,8-i);
      |                                ^~
a.cc:121:32: note: 'double d1' previously declared here
  121 |                         double d1=pro[i];
      |                                ^~
a.cc:126:32: error: redeclaration of 'double d2'
  126 |                         double d2=(kai[8]/(kai[j]*kai[8-j]))*pow(0.25,j)*pow(0.75,8-j);
      |                                ^~
a.cc:122:32: note: 'double d2' previously declared here
  122 |                         double d2=pro[j];
      |                                ^~
a.cc:127:32: error: redeclaration of 'double d3'
  127 |                         double d3=(kai[8]/(kai[k]*kai[8-k]))*pow(0.25,k)*pow(0.75,8-k);
      |                                ^~
a.cc:123:32: note: 'double d3' previously declared here
  123 |                         double d3=pro[k];
      |                                ^~
a.cc:128:32: error: redeclaration of 'double d4'
  128 |                         double d4=(kai[8]/(kai[l]*kai[8-l]))*pow(0.25,l)*pow(0.75,8-l);
      |                                ^~
a.cc:124:32: note: 'double d4' previously declared here
  124 |                         double d4=pro[l];
      |                                ^~