题目:http://acm.hdu.edu.cn/showproblem.php?pid=3315
思路:建图很简单,不过因为要使原匹配改变最小,处理方法和HDU 2853一样,不多说了
总结:理解错了题意,当出场次序改变时,它的伤害值对应仍不变,我以为是对应如今的出场次序,然后样例过的很完美。。。醉了醉了。。。
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
const int N = 100;
const int INF = 0x3f3f3f3f;
int nx, ny;
int lx[N], ly[N], slack[N], match[N], s[N][N];
bool visx[N], visy[N];
bool hungary(int v)
{
visx[v] = true;
for(int i = 1; i <= ny; i++)
{
if(visy[i]) continue;
if(lx[v] + ly[i] == s[v][i])
{
visy[i] = true;
if(match[i] == -1 || hungary(match[i]))
{
match[i] = v;
return true;
}
}
else slack[i] = min(slack[i], lx[v] + ly[i] - s[v][i]);
}
return false;
}
void km()
{
memset(match, -1, sizeof match);
memset(ly, 0, sizeof ly);
for(int i = 1; i <= nx; i++)
lx[i] = -INF;
for(int i = 1; i <= nx; i++)
for(int j = 1; j <= ny; j++)
lx[i] = max(lx[i], s[i][j]);
for(int i = 1; i <= nx; i++)
{
memset(slack, 0x3f, sizeof slack);
while(true)
{
memset(visx, 0, sizeof visx);
memset(visy, 0, sizeof visy);
if(hungary(i)) break;
else
{
int d = INF;
for(int j = 1; j <= ny; j++)
if(!visy[j]) d = min(d, slack[j]);
for(int j = 1; j <= nx; j++)
if(visx[j]) lx[j] -= d;
for(int j = 1; j <= ny; j++)
if(visy[j]) ly[j] += d;
else slack[j] -= d;
}
}
}
}
int main()
{
int n;
int v[N], h[N], p[N], a[N], b[N];
while(scanf("%d", &n), n)
{
for(int i = 1; i <= n; i++) scanf("%d", v + i);
for(int i = 1; i <= n; i++) scanf("%d", h + i);
for(int i = 1; i <= n; i++) scanf("%d", p + i);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(int i = 1; i <= n; i++) scanf("%d", b + i);
memset(s, 0, sizeof s);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
int t1 = p[j] / a[i] + ((p[j] % a[i] == 0) ? 0 : 1);
int t2 = h[i] / b[j] + ((h[i] % b[j] == 0) ? 0 : 1);
if(t1 <= t2) s[i][j] = v[i] * 100;
else s[i][j] = -v[i] * 100;
if(i == j) s[i][j] += 1;
}
nx = ny = n;
km();
int res = 0;
for(int i = 1; i <= ny; i++)
res += s[match[i]][i];
if(res > 0) printf("%d %.3f%%\n", res / 100, 100.0 * (res % 100) / n);
else printf("Oh, I lose my dear seaco!\n");
}
return 0;
}