跳到正文

题解

题解:P6915 [ICPC 2015 WF] Weather Report

用户 1674785约 3 分钟
原文

这是 2025年9月16日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟
题目
P6915

版本

  1. v2当前
  2. v1

这是我的成名之作

C++
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
LL c[50][50];
int n;
double p[5];
#define mp make_pair
#define pii pair<double,LL> 
priority_queue<pii,vector<pii>,greater<pii> > q;
int main(){
	cin>>n;
	F(i,0,n){
		c[i][0]=1;
		F(j,1,i){
			c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
	}
	F(i,1,4){
		cin>>p[i];
	}
	double tx=1;
	LL num=1;
	F(i,0,n){
		double ty=1;
		if (i) num/=c[n][i-1];
		num*=c[n][i];
		F(j,0,n-i){
			double tz=1;
			if (j) num/=c[n-i][j-1];
			num*=c[n-i][j];
			F(k,0,n-j-i){
				if (k) num/=c[n-i-j][k-1];
				num*=c[n-i-j][k];
				double tmp=tz*tx*ty;
				F(l,1,n-i-k-j){
					tmp=tmp*p[4];
				}
//				cout<<tmp<<" "<<num<<" "<<i<<" "<<j<<" "<<k<<"\n";
				q.push(mp(tmp,num));	
				tz*=p[3];
			}
			ty*=p[2];
		}
		tx*=p[1];
	}
	double ans=0;
	while (q.size()>1){
		pii tmp=q.top(); q.pop();
		if (tmp.second>=2){
			ans+=tmp.first*2*(tmp.second/2);
			q.push(mp(tmp.first*2,tmp.second/2));
		}
		if (tmp.second&1){
			pii tt=q.top(); q.pop();
			ans+=tmp.first+tt.first;
			q.push(mp(tmp.first+tt.first,1));
			if (tt.second>1){
				q.push(mp(tt.first,tt.second-1));
			}
		}
//		cout<<ans<<"\n";
	}
	cout<<setprecision(10)<<fixed<<ans<<"\n";
	return 0; 
}