結果
問題 | No.453 製薬会社 |
ユーザー | chaemon |
提出日時 | 2016-12-04 00:07:44 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 4,078 bytes |
コンパイル時間 | 1,111 ms |
コンパイル使用メモリ | 99,456 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-05 15:59:18 |
合計ジャッジ時間 | 1,690 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
ソースコード
// #includes {{{ #include <algorithm> #include <numeric> #include <iostream> #include <string> #include <vector> #include <queue> #include <list> #include <deque> #include <stack> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cassert> #include <cstring> #include <cmath> using namespace std; // }}} // pre-written code {{{ #define REP(i,n) for(int i=0;i<(int)(n);++i) #define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i) #define LET(x,a) __typeof(a) x(a) //#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i) #define ALL(c) (c).begin(), (c).end() #define MP make_pair #define EXIST(e,s) ((s).find(e)!=(s).end()) #define RESET(a) memset((a),0,sizeof(a)) #define SET(a) memset((a),-1,sizeof(a)) #define PB push_back #define DEC(it,command) __typeof(command) it=command const int INF=0x3f3f3f3f; typedef long long Int; typedef unsigned long long uInt; #ifdef __MINGW32__ typedef double rn; #else typedef long double rn; #endif typedef pair<int,int> pii; /* #ifdef MYDEBUG #include"debug.h" #include"print.h" #endif */ // }}} typedef vector<double> arr; typedef vector<arr> matrix; const double EPS = 1e-8; enum { OPTIMAL, UNBOUNDED, NOSOLUTION, UNKNOWN }; struct two_stage_simplex { int N, M, st; matrix a; vector<int> s; two_stage_simplex(const matrix &A, const arr &b, const arr &c) : N(A.size()), M(A[0].size()), a(N+2, arr(M+N+1)), s(N+2), st(UNKNOWN) { for (int j = 0; j < M; ++j) a[N+1][j] = c[j]; // make simplex table for (int i = 0; i < N; ++i) for (int j = 0; j < M; ++j) a[i+1][j] = A[i][j]; for (int i = 0; i < N; ++i) a[i+1][M+N] = b[i]; // add helper table for (int i = 0; i < N; ++i) a[ 0 ][i+M] = 1; for (int i = 0; i < N; ++i) a[i+1][i+M] = 1; for (int i = 0; i < N; ++i) s[i+1] = i+M; for (int i = 1; i <= N; ++i) for (int j = 0; j <= N+M; ++j) a[0][j] += a[i][j]; st = solve(); } int status() const { return st; } double solution() const { return -a[0][M]; } double solution(arr &x) const { x.resize(M, 0); for (int i = 0; i < N; ++i) x[s[i+1]] = a[i+1].back(); return -a[0][M]; } int solve() { M += N; N += 1; solve_sub(); // solve stage one if (solution() > EPS) return NOSOLUTION; N -= 1; M -= N; swap(a[0], a.back()); a.pop_back(); // modify table for (int i = 0; i <= N; ++i) { swap(a[i][M], a[i].back()); a[i].resize(M+1); } return solve_sub(); // solve stage two } int solve_sub() { int p, q; while (1) { //print(); for (q = 0; q <= M && a[0][q] >= -EPS; ++q); for (p = 0; p <= N && a[p][q] <= EPS; ++p); if (q >= M || p > N) break; for (int i = p+1; i <= N; ++i) // bland's care for cyclation if (a[i][q] > EPS) if (a[i][M]/a[i][q] < a[p][M]/a[p][q] || (a[i][M]/a[i][q] == a[p][M]/a[p][q] && s[i] < s[q])) p = i; pivot(p, q); } if (q >= M) return OPTIMAL; else return UNBOUNDED; } void pivot(int p, int q) { for (int j = 0; j <= N; ++j) for (int k = M; k >= 0; --k) if (j != p && k != q) a[j][k] -= a[p][k]*a[j][q]/a[p][q]; for (int j = 0; j <= N; ++j) if (j != p) a[j][q] = 0; for (int k = 0; k <= M; ++k) if (k != q) a[p][k] = a[p][k]/a[p][q]; a[p][q] = 1.0; s[p] = q; } }; /* int main() { for (int n, m; cin >> n >> m; ) { arr c(n+m), b(m); for (int i = 0; i < n; ++i) cin >> c[i], c[i] *= -1; matrix A(m, arr(n+m)); for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) cin >> A[i][j]; A[i][n+i] = 1; cin >> b[i]; } two_stage_simplex tss(A, b, c); double ans = -tss.solution() * m; printf("Nasa can spend %.0f taka.\n", ans + 0.5 - EPS); } } */ int main(){ int C,D; cin>>C>>D; matrix A(2,arr(4,0.0)); A[0][0] = 3.0/4.0; A[0][1] = 2.0/7.0; A[1][0] = 1.0/4.0; A[1][1] = 5.0/7.0; A[0][3] = 1.0; A[1][4] = 1.0; arr b(2); b[0] = C; b[1] = D; arr c(2); c[0] = -1000.0; c[1] = -2000.0; two_stage_simplex tss(A,b,c); double ans = -tss.solution(); printf("%.10lf\n",ans); return 0; }