Compare commits

..

No commits in common. "dc8c32391023cc04783efb10b29da462e105b61b" and "0d64ce82d3644bd652a7b8a9f8c53ed02bd22774" have entirely different histories.

3 changed files with 67 additions and 79 deletions

View File

@ -1,3 +0,0 @@
int main(){
}

View File

@ -1,73 +0,0 @@
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <istream>
#include <print>
#include <vector>
using ll = int64_t;
const ll maxa=5e6+5;
std::vector<ll> t;
std::bitset<maxa> isp;
static inline void solve(){
ll n;
std::cin>>n;
// a.clear();
// a.resize(n+1);
ll minn = 1e9+7;
ll a=-1;
for(ll i=1;i<=n;i++){
ll tmp;
std::cin>>tmp;
if(t[tmp]<minn){
minn=t[tmp];
a=tmp;
}
}
if(!(a%4)){
std::cout<<"Farmer Nhoj\n";
}else{
std::cout<<"Farmer John\n";
}
}
int main(){
std::iostream::sync_with_stdio(false);
std::cin.tie(nullptr);
isp.set();
for(ll i=2;i<isp.size();i++){
if(!isp[i])continue;
for(ll j=2;i*j<isp.size();j++){
isp[i*j]=false;
}
}
// for(ll i=1;i<=100;i++)if(isp[i])std::cout<<i<<"\n";
t.resize(maxa);
for(ll i=1;i<t.size();i++){
if((i&1)==0){
t[i]=i/4;
continue;
}
ll nt=0,ni=i;
while(ni>=4){
if(isp[ni]){
t[i]=nt;
break;
}
nt++;
ni-=4;
}
// printf("t[%lld]=%lld\n",i,t[i]);
}
// for(ll i=1;i<=100;i++)printf("t[%lld]=%lld\n",i,t[i]);
ll T;
std::cin>>T;
while(T--){
solve();
}
}

View File

@ -1,3 +1,67 @@
int main(){ #include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <iomanip>
// 使用 C++11 的随机数生成工具,比 rand() 质量更高
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
/**
* @brief [min, max]
* @param min
* @param max
* @return
*/
double random_double(double min, double max) {
std::uniform_real_distribution<double> dist(min, max);
return dist(rng);
}
int main() {
// 设置 IO 加速,在 OI/ACM 竞赛中常用
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
// --- 问题参数 ---
const double L = 3.0; // 木棍总长度
const int NUM_TRIALS = 10000000; // 模拟试验次数,次数越多结果越接近理论值
int success_count = 0; // 能够构成三角形的成功次数
// --- 蒙特卡洛模拟 ---
for (int i = 0; i < NUM_TRIALS; ++i) {
// 1. 在木棍上随机选择两个断点
double break1 = random_double(0.0, L);
double break2 = random_double(0.0, L);
// 2. 确定两个断点的位置,方便计算三段长度
double p1 = std::min(break1, break2);
double p2 = std::max(break1, break2);
// 3. 计算三段的长度
double seg1 = p1;
double seg2 = p2 - p1;
double seg3 = L - p2;
// 4. 检查是否能构成三角形
// 充要条件:任意一边的长度都小于总长度的一半
double half_L = L / 2.0;
if (seg1 < half_L && seg2 < half_L && seg3 < half_L) {
success_count++;
}
}
// --- 输出结果 ---
double probability = static_cast<double>(success_count) / NUM_TRIALS;
std::cout << "--- 蒙特卡洛模拟解决木棍折断问题 ---" << std::endl;
std::cout << "木棍长度 (L): " << L << std::endl;
std::cout << "模拟次数 (N): " << NUM_TRIALS << std::endl;
std::cout << "成功次数: " << success_count << std::endl;
std::cout << std::fixed << std::setprecision(6);
std::cout << "模拟得到的概率 P ≈ " << probability << std::endl;
std::cout << "理论概率 P = 0.25" << std::endl;
return 0;
} }