NO IMAGE

在世界盃用程式實現一個買彩票的最優選擇豈不是美哉,接下來是程式。

#include<iostream>
using namespace std;
float S, P, F, sp, pp, fp, sm, pm;;
extern float e[4];
void est(float sp, float pp, float fp)
{
	float s[4] = { 0 }, f[4] = { 0 }, p[4] = { 0 }, temp[3] = { 0 }, e[3] = { 0 }, sm = 50, pm = 0;
	for (sm = 50; sm >= 0 ; sm--)
	{
		for (pm = 0; pm<= 50-sm; pm  )
		{
			temp[0] = e[0];
			temp[1] = e[1];
			temp[2] = e[2];
			e[0] = S*(sp*sm - pm - (50 - sm - pm)) ;
			e[1] = P*(pp*pm - sp - (50 - sm - pm));
			e[2] = F*((50 - sm - pm)*fp - sm - pm);

			if (e[0] > temp[0])
			{
				s[0] = e[0];
				s[1] = sm;
				s[2] = pm;
				s[3] = 50-sm-pm;
			}
			if (e[1] > temp[1])
			{
				p[0] = e[1];
				p[1] = sm;
				p[2] = pm;
				p[3] = 50 - sm - pm;
			}
			if (e[2] > temp[2])
			{
				f[0] = e[2];
				f[1] = sm;
				f[2] = pm;
				f[3] = 50 - sm - pm;
			}
		}
	}
	cout << "勝的情況下:投注的金額分別為:勝" << s[1] << ";平:" << s[2] << ";負:" << s[3] << endl;
	cout << "最大獲利為:" << s[0] << endl;
	cout << "平的情況下:投注的金額分別為:勝" << p[1] << ";平:" <<p[2] << ";負:" << p[3] << endl;
	cout << "最大獲利為:" << p[0] << endl;
	cout << "負的情況下:投注的金額分別為:勝" << f[1] << ";平:" << f[2] << ";負:" << f[3] << endl;
	cout << "最大獲利為:" << f[0] << endl;
}
int main()
{
	cout << "Please enter the value of S,P,F:";
	cin >> S >> P >> F;
	cout << "Please enter the value of sp,pp,fp:";
	cin >> sp >> pp >> fp;
	est(sp, pp, fp);
	cin >> S;
	return 0;
}

如果你有更好的核心演算法思路,歡迎交流~~