#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const double EPS = 1.0e-10; // 行列の基本変形を行い、行列のランクを返す int elementaryMatrix(vector >& mat) { const int n = mat.size(); const int m = mat[0].size(); int y = 0; int x = 0; while(y < n && x < m){ int tmp = y; for(int i=y+1; i abs(mat[tmp][x])) tmp = i; } if(abs(mat[tmp][x]) > EPS){ mat[y].swap(mat[tmp]); for(int i=y+1; i=x; --j){ mat[i][j] -= mat[y][j] * (mat[i][x] / mat[y][x]); } } ++ y; } ++ x; } mat.resize(y); return y; } // 連立方程式の解を求める bool linearSystem(vector >& mat, vector& x) { int n = mat[0].size() - 1; if(elementaryMatrix(mat) != n || mat[n-1][n-1] == 0) return false; x.resize(n); for(int i=n-1; i>=0; --i){ x[i] = mat[i][n]; for(int j=i+1; j> c >> d; double ans = 0.0; for(int i=0; i<2; ++i){ double x = min(c / MATERIAL[i][0], d / MATERIAL[i][1]); ans = max(ans, x * VALUE[i]); } vector > mat = { {MATERIAL[0][0], MATERIAL[1][0], c}, {MATERIAL[0][1], MATERIAL[1][1], d}, }; vector x; linearSystem(mat, x); if(x[0] > 0 && x[1] > 0) ans = max(ans, x[0] * VALUE[0] + x[1] * VALUE[1]); printf("%.10f\n", ans); return 0; }