Sub sub_dist()
Dim c As Range '用于选定某一格
Count = 0 '统计符合条件的样品数
'对选定区域的每一格进行操作
For Each c In Range("a2:a5875")
If c.Value > 0 And c.Value <= 10 Then '如果当格数据满足大于0不超过10,则计数加1
Count = Count + 1
End If
Next c
Range("a5875").Value = Count '在a5875这一格显示统计数据
End Sub
#include // std::cout
#include // std::next_permutation, std::sort
using namespace std;
int myints[] = {1,2,3,4,5,6,7,8}; // Represents the flowers. Rank 8 means the most beautiful one.
int success_times = 0; // Record how many times are succeed.
// This function checks if the current array can make platon succeed to find the most beautiful flower.
// if it does, increse the success_times by 1 and return true, otherwise return false.
bool check_succeed(){
int biggest_num_in_first_three = 0;
// Get the biggest number in the first three places.
for(int i=0; i<3; i++){
if(myints[i]>biggest_num_in_first_three) biggest_num_in_first_three = myints[i];
}
if (biggest_num_in_first_three == 8) return false;
// Find the first number that bigger than the biggest_num_in_first_three;
int result = 0;
for(int i=3; i<8; i++){
if(myints[i]>biggest_num_in_first_three){
result = myints[i];
break;
}
}
if(result == 8){
success_times++;
return true;
}
return false;
}
int main () {
sort (myints,myints+8);
do {
check_succeed();
} while ( std::next_permutation(myints,myints+8) );
cout << success_times<<'\n'; // Print out success times.
cout << (float)success_times/(8*7*6*5*4*3*2*1); // Print out the probability.
return 0;
}