First for each possible PK situation to determine the outcome, and then the minimum change to the maximum match.
#include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm > #include <fstream> #include <iostream> #include <cctype> #define REP (i, L, R) for (int i=l; i<=r; i + +) #define CLR (x, C) memset (x, C, sizeof (x)) #define MAX 0x3fffffff#define N 100using namespace Std;int read () {int x=0; cha R Ch=getchar (); while (!isdigit (CH)) Ch=getchar (), while (IsDigit (ch)) {x=x*10+ch-' 0 '; Ch=getchar ();} return x;} int n, L[n], st[n], lx[n], ly[n], v[n][n], a1[n], a2[n], hp1[n], hp2[n], P[n];bool vx[n], vy[n];inline int PK (int x, int y {int c=min (hp1[x]-1)/a2[y], (hp2[y]-1)/a1[x]) +1; if (C*a1[x]>=hp2[y]) return p[x]; else return-p[x];} BOOL Find (int x) {vx[x]=1;rep (y, 1, N) if (!vy[y]) {int a=lx[x]+ly[y]-v[x][y];if (!a) {vy[y]=1; if (!l[y] | | Find (L[y])) {l[y]=x; return 1;}} else St[y]=min (St[y], a);} return 0;} inline int km () {clr (ly, 0), CLR (l, 0), Rep (i, 1, N) lx[i]=-max;rep (i, 1, N) Rep (j, 1, N) if (Lx[i]<v[i][j]) lx[i]=v[i][ J];Rep (i, 1, N) {rep (j, 1, N) st[j]=max;while (1) {CLR (VX, 0), CLR (vy, 0), if (Find (i)) break, int A=max;rep (j, 1, N) if (!vy[j] && A>st[j]) A=st[j];rep (j, 1, N) if (Vx[j]) Lx[j]-=a;rep (j, 1, N) if (vy[j]) ly[j]+=a; else St[j]-=a;}} int A=0;rep (i, 1, N) a+=lx[i]+ly[i];return A;} int main () {while (~SCANF ("%d", &n) && N) {Rep (i, 1, N) p[i]=read (); Rep (i, 1, N) hp1[i]=read (); Rep (i, 1, N) hp2[ I]=read (); Rep (i, 1, N) a1[i]=read (); Rep (i, 1, N) a2[i]=read (); Rep (i, 1, N) Rep (j, 1, N) v[i][j]=pk (i, J); Rep (i, 1, N) Rep ( J, 1, N) v[i][j]*=n, V[i][j]+=i==j?1:0;int ans=km (); Double k=ans%n;if (ans>0) printf ("%d%.3lf%%\n", ans/n, k/n*100); else printf ("Oh, I lose my dear seaco!\n");} return 0;}
HDU-3315 My Brute