Skip to content

Instantly share code, notes, and snippets.

@peienwu
Last active May 20, 2022 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peienwu/280fbfccd5dfee912a055a2bd9b3149e to your computer and use it in GitHub Desktop.
Save peienwu/280fbfccd5dfee912a055a2bd9b3149e to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#define ld long double
#define IOS ios::sync_with_stdio(0),cout.tie(0)
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
char table[10][10];
//H->健康、Q->隔離、X->確診
void init(){
for(int i = 1;i <= 6;i++){
for(int j = 1;j <= 6;j++){
table[i][j] = 'H';
}
}
}
pii pos(int x){
x--;
pii ret = {x/6+1,x%6+1};
return ret;
}
bool check(pii pos){
bool f = 0;
if(table[pos.ff][pos.ss] == 'X')return 0;
for(int i = max(pos.ff-1,1);i <= min(pos.ff+1,6);i++){
for(int j = max(pos.ss-1,1);j <= min(pos.ss+1,6);j++){
if(table[i][j] == 'X'){f = 1;break;}
}
}
if(f == 1)table[pos.ff][pos.ss] = 'Q';
return f;
}
int main(){
IOS;
int times = 0,t1 = 0,t2 = 0;
ld posibility = 0.0,pside = 0.0,pedge = 0.0;
for(int a = 1;a <= 36;a++){
for(int b = a+1;b <= 36;b++){
for(int c = b+1;c <= 36;c++){
for(int d = c+1;d <= 36;d++){
init();
int temp = 0;
table[pos(a).ff][pos(a).ss] = 'X';
table[pos(b).ff][pos(b).ss] = 'X';
table[pos(c).ff][pos(c).ss] = 'X';
table[pos(d).ff][pos(d).ss] = 'X';
for(int i = 1;i <= 6;i++){
for(int j = 1;j <= 6;j++){
check({i,j});
}
}
for(int i = 1;i <= 6;i++){
for(int j = 1;j <= 6;j++){
if(table[i][j] == 'H'){temp++;}
}
}
posibility += (ld)temp / 32;
times ++;
for(int i = 1;i <= 6;i++){
for(int j = 1;j <= 6;j++){
cout<<table[i][j]<<" ";
}
cout<<endl;
}
cout<<"不用匡列數量:"<<temp<<endl;
cout<<"不用匡列機率:"<<(ld)temp / 32<<endl;
if(table[1][1]!='X'){
if(table[1][1]=='Q'){
pedge++;
cout<<"角落被匡"<<endl;
}
t1++;
}
if(table[2][1]!='X'){
if(table[2][1]=='Q'){
pside++;
cout<<"靠邊被匡"<<endl;
}
t2++;
}
}
}
}
}
posibility /= (ld)times;
pedge /= (ld)t1;
pside /= (ld)t2;
cout<<times<<endl;
cout<<fixed<<setprecision(6);
cout<<"隨機坐不被匡機率:"<<posibility<<endl;
cout<<"坐角落不被匡機率:"<<1 - pedge<<endl;
cout<<"坐靠邊不被匡機率:"<<1 - pside<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment