QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#79423 | #2457. Cheese, If You Please | kexun | WA | 2ms | 3820kb | C++14 | 1.5kb | 2023-02-20 08:17:29 | 2023-02-20 08:17:30 |
Judging History
answer
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
const int N = 105, M = 105;
const long double eps=1e-10;
int n, m, id[105];
long double a[55][55], ans[55];
void Pivot(int l, int e) {
swap(id[l + n], id[e]);
long double t = a[l][e];
a[l][e]=1;
for (int i = 0; i <= n; ++i) a[l][i] /= t;
for (int i = 0; i <= m; ++i)
if (i != l && fabs(a[i][e]) > eps) {
t = a[i][e];
a[i][e] = 0;
for (int j = 0; j <= n; ++j)
a[i][j] -= t * a[l][j];
}
}
bool Simplex() {
while (1) {
int l = 0, e = 0;
long double mn = 1e+50;
for (int i = 1; i <= n; ++i)
if (a[0][i] > eps) {
e = i;
break;
}
if (!e) break;
for (int i = 1; i <= m; ++i)
if (a[i][e] > eps && a[i][0] / a[i][e] < mn)
mn = a[i][0] / a[i][e], l = i;
if (!l) return false;
Pivot(l, e);
}
return true;
}
int main() {
cin >> m >> n;
for (int i = 1; i <= m; ++i) cin >> a[i][0];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[j][i];
a[j][i] /= 100;
}
cin >> a[0][i];
}
for (int i = 1; i <= n; ++i) id[i] = i;
if (Simplex()) {
double ans = -a[0][0];
printf("%.2lf\n", ans);
}
else while(1);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3820kb
input:
4 4 100 0 123 456 10.0 20.0 30.0 40.0 2.56 40.0 0.0 25.0 35.0 3.84 40.0 30.0 20.0 10.0 1.23 33.0 0.0 34.0 33.0 4.23
output:
1281.82
result:
ok single line: '1281.82'
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3704kb
input:
4 4 0 0 0 0 10.0 20.0 30.0 40.0 2.56 40.0 0.0 25.0 35.0 3.84 40.0 30.0 20.0 10.0 1.23 33.0 0.0 34.0 33.0 4.23
output:
-0.00
result:
wrong answer 1st lines differ - expected: '0.00', found: '-0.00'