Test instructions
Several of the sequence a[] are given, the known sequence satisfies non-subtraction, and 0 <= ai <= 100, q (A1 + A2)/(∑ai) The maximum possible number of
Analysis:
Ensure the A1,A2 as large as possible and the rest as small as possible
1#include <iostream>2#include <cstring>3 using namespacestd;4 intt, N, M;5 inta[ the];6 intGCD (intAintb)7 {8 returnb = =0? A:GCD (b, a%b);9 }Ten intMain () One { Ascanf"%d", &t); - while(t--) - { theMemset (A,-1,sizeof(a)); -scanf"%d%d", &n, &m); - if(M = =0|| n = =2) - { +Puts"1/1");Continue; - } + for(inti =1; I <= m; i++) A { at intx, y; -scanf"%d%d", &x, &y); -A[X] =y; - } - intmin=0; - for(inti = n; i >2; i--) in { - if(A[i] = =-1) A[i] =Min; to ElseMin =A[i]; + } - if(a[1] == -1) a[1] = -; the if(a[2] == -1) a[2] = a[1]; * intTu = a[1] + a[2], TD =0; $ for(inti =1; I <= N; i++) td + =A[i];Panax Notoginseng intGCD =GCD (TU, TD); -Tu/=gcd; theTD/=gcd; +printf"%d/%d\n", Tu, TD); A } the}
HDU 5742-it ' s All in the mind