CF1543C. Need for Pink Slips
题意:
题解:
其实具体的计算方法在说明里面都写了:对于第一个数据:
0.2 0.2 0.6 0.2
组成方案如下:
就是c和m如果大于v就减,小于v就变成0,到p直接停止
所以直接dfs暴力就完事了
注意:已经消失的不会再被平均,如果M已经是0了,当C平均分时就不考虑M
代码:
#include <bits/stdc++.h>
#include <unordered_map>
#define debug(a, b) printf("%s = %d\n", a, b);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
clock_t startTime, endTime;
//Fe~Jozky
const ll INF_ll= 1e18;
const int INF_int= 0x3f3f3f3f;
void read(){};
template <typename _Tp, typename... _Tps> void read(_Tp& x, _Tps&... Ar)
{x= 0;char c= getchar();bool flag= 0;while (c < '0' || c > '9')flag|= (c == '-'), c= getchar();while (c >= '0' && c <= '9')x= (x << 3) + (x << 1) + (c ^ 48), c= getchar();if (flag)x= -x;read(Ar...);
}
template <typename T> inline void write(T x)
{if (x < 0) {x= ~(x - 1);putchar('-');}if (x > 9)write(x / 10);putchar(x % 10 + '0');
}
void rd_test()
{
#ifdef ONLINE_JUDGE
#elsestartTime = clock ();freopen("data.in", "r", stdin);
#endif
}
void Time_test()
{
#ifdef ONLINE_JUDGE
#elseendTime= clock();printf("\nRun Time:%lfs\n", (double)(endTime - startTime) / CLOCKS_PER_SEC);
#endif
}
double eps=1e-7;
double ans=0;
double v;
stack<int>s;
void dfs(double c,double m,double p,string s,double w){double add1=0,add2=0;bool f1=0,f2=0;if(c>=v){if(abs(m)>eps)f1=1;if(abs(p)>eps)f2=1;if(f1&&f2){add1=add2=v/2.0;}else if(f1){add1=v;}else if(f2){add2=v;}dfs(c-v,m+add1,p+add2,s+"c",w*c);}if(c<v&&abs(c)>eps){if(abs(m)>eps)f1=1;if(abs(p)>eps)f2=1;if(f1&&f2){add1=add2=c/2.0;}else if(f1){add1=c;}else if(f2){add2=c;}dfs(0,m+add1,p+add2,s+"c",w*c);}if(m>=v){if(abs(c)>eps)f1=1;if(abs(p)>eps)f2=1;if(f1&&f2){add1=add2=v/2.0;}else if(f1){add1=v;}else if(f2){add2=v;}dfs(c+add1,m-v,p+add2,s+"m",w*m);}if(m<v&&abs(m)>eps){if(abs(c)>eps)f1=1;if(abs(p)>eps)f2=1;if(f1&&f2){add1=add2=m/2.0;}else if(f1){add1=m;}else if(f2){add2=m;}dfs(c+add1,0,p+add2,s+"m",w*m);}if(p){
// printf("w=%.6f\n",w*p);
// cout<<"w="<<w<<endl;string xx=s+"p";ans+=xx.length()*w*p;// printf("%s\n",xx.c_str());
// cout<<s+"p"<<endl;}return ;
}
int main()
{//rd_test();int t;read(t);while(t--){ans=0;double c,m,p;cin>>c>>m>>p>>v;dfs(c,m,p,"",1);printf("%.8f\n",ans);}//Time_test();
}