Hdu3315/optimal matching of the maximum right (do not change the order if possible under the maximum right) (The right to Tianji horse racing issues)/billing Flow

Source: Internet
Author: User

Question: two people have scores in each game. Each person sends a holy beast (brute). The dictionary is translated as an animal. I don't think it is a perfect match ), attack Power and blood strip... A bunch of rules...

Make reasonable arrangements to get the maximum score for the first person, and try not to change the original order of appearance (, 3... N), and obtain the similarity (number of fields not changed/N)

Idea: clearly build a bipartite graph. If you win, even the negative side means the positive side, X-> Y, and then run the S-> T charge stream, the key to the question is how to stream the I --> I 'edge as much as possible at the maximum cost ,:Principal cost Extension Method!The cost is slightly larger than N. Here it is 100 times larger. If it is an I --> I 'side, the cost will be-1 (maximum-N does not affect the total cost ), so after the final result is negative, if ans <100 (equivalent to the cost stream 0) loses, the result is ANS/100, the number of edges taking I --> I 'is ans % 100 (natural ).

PS: it has been adjusted for a long time because the question is not fully understood! The score for the I game is subject to the number of the holy beast of the Character 1! See the example first!

# Include <cstdio> # include <iostream> # include <queue> # include <cstring> using namespace STD; const int maxv = 200; const int MaxE = 200*200*2 + 800; const int INF = 0x3f3f3f; int nume = 0; int e [MaxE] [4]; int head [maxv]; int n, m, K; void inline Adde (int I, Int J, int C, int W) {e [nume] [0] = J; E [nume] [1] = head [I]; head [I] = nume; E [nume] [2] = C; E [nume ++] [3] = W; E [nume] [0] = I; E [nume] [1] = head [J]; head [J] = nume; E [nume] [2] = 0; E [nume ++] [3] =- W;} int INQ [maxv]; int pre [maxv]; int PRV [maxv]; int d [maxv]; int Val [maxv]; int Hi [maxv]; int PI [maxv]; int Ai [maxv]; int Bi [maxv]; // Val the score corresponding to this holy beast (based on US) Pi: My holy animal blood, hi, enemy blood, AI, attack power, Bi, attack power bool spfa (Int & sum, Int & flow) {int S = 2 * n, t = 2 * n + 1; for (INT I = 0; I <= T; I ++) {INQ [I] = 0; d [I] = inf;} queue <int> q; q. push (s); INQ [s] = 1; d [s] = 0; while (! Q. empty () {int cur = Q. front (); q. pop (); INQ [cur] = 0; For (INT I = head [cur]; I! =-1; I = E [I] [1]) {int v = E [I] [0]; if (E [I] [2]> 0 & D [cur] + E [I] [3] <D [v]) {d [v] = d [cur] + E [I] [3]; Pre [v] = I; PRV [v] = cur; If (! INQ [v]) {q. push (V); INQ [v] = 1 ;}}} if (d [T] = inf) return 0; int cur = T; int minf = inf; while (cur! = S) {int Fe = pre [cur]; minf = E [Fe] [2] <minf? E [Fe] [2]: minf; cur = PRV [cur];} cur = T; while (cur! = S) {e [pre [cur] [2]-= minf; E [pre [cur] ^ 1] [2] + = minf; cur = PRV [cur];} flow + = minf; sum + = d [T] * minf; return 1;} int mincost (Int & flow) {int sum = 0; while (spfa (sum, flow); Return sum;} void Init () {nume = 0; For (INT I = 0; I <= N * 2 + 2; I ++) head [I] =-1;} bool getres (INT xph, int XF, int yph, int YF) // can I win {int count1 with this match, count2; If (xph % YF! = 0) count1 = xph/YF + 1; else count1 = xph/YF; If (yph % XF! = 0) count2 = yph/XF + 1; else count2 = yph/XF; If (count1> = count2) return 1; else return 0;} void read_build () {for (Int J = 0; j <n; j ++) scanf ("% d", & Val [J]); For (Int J = 0; j <n; j ++) scanf ("% d", & Hi [J]); For (Int J = 0; j <n; j ++) scanf ("% d", & PI [J]); For (Int J = 0; j <n; j ++) scanf ("% d ", & Ai [J]); For (Int J = 0; j <n; j ++) scanf ("% d", & BI [J]); for (INT I = 0; I <n; I ++) for (Int J = 0; j <n; j ++) {If (getres (Hi [I], ai [I], PI [J], Bi [J]) {if (I! = J) // charges-1 Adde (I, j + N, 1,-Val [I] * 100); else Adde (I, j + N, 1,-Val [I] * 100-1);} else {if (I! = J) Adde (I, j + N, 1, Val [I] * 100); else Adde (I, j + N, 1, val [I] * 100-1) ;}}for (INT I = 0; I <n; I ++) {Adde (2 * n, I, 1, 0 ); ADDE (I + N, 2 * n + 1, 1, 0);}/* For (INT I = 0; I <= 2 * n + 1; I ++) for (Int J = head [I]; J! =-1; j = E [J] [1]) {printf ("% d-> % d: F % DW % d \ n", I, E [J] [0], E [J] [2], E [J] [3]);} */} int main () {While (~ Scanf ("% d", & N) & n! = 0) {Init (); read_build (); int flow = 0; int ans =-mincost (flow); If (ANS <100) // here is <100, because it has been reversed now! Printf ("oh, I lose my dear seaco! \ N "); else printf (" % d %. 3f % \ n ", ANS/100, (ANS % 100) * 1.0/N * 100);} return 0 ;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.