Poj 2287 Tian Ji -- The Horse Racing
Poj 2287 Tian Ji -- The Horse Racing
Question:
Tianji horse racing
If three horses are changed to 1000, Qi Wang still sets his horse to compete in the order of superiority to inferiority. Tian Ji can select his horse racing in any order. If you win a game, Tian Ji will get 200 silver coins. If you lose one game, Tian Ji will lose 200 silver coins.
How much money can Tian Ji win at most?
Ideas:
Greedy;
If Marco is the best horse to win the best horse of the king, make the two horses match each other;
If the worst horse can win the worst horse of Qi Wang at present, the two horses will match each other;
If neither of the above conditions is met, make the worst horse and the best horse match of Qi Wang.
/* Poj 2287 question: if three horses are converted into 1000 horses, Qi Wang still sets his horse to compete in the order of superiority to inferiority, tian Ji can select his horse racing competition in any order. If you win a game, Tian Ji will get 200 silver coins. If you lose one game, Tian Ji will lose 200 silver coins. How much money can Tian Ji win at most? Idea: greedy; if Marco is the best horse to win King Qi, the two horses will match each other; if the worst horse can win King Qi's worst horse, make the two horses match each other. If neither of the above conditions is met, make the worst horse and the best horse of Qi Wang match each other. */# Include
# Include
# Define deusing namespace std; const int N = 1005; int a [N], B [N]; void gao (int n) {int p1 = 0, p2 = 0; int q1 = n-1, q2 = n-1; int ans = 0; while (p1 <= q1) {if (a [p1]> B [p2]) {++ p1; ++ p2; ++ ans;} else if (a [q1]> B [q2]) {-- q1; -- q2; ++ ans ;} else {if (a [p1]! = B [q2]) -- ans; ++ p1; -- q2 ;}} printf (% d, ans * 200);} int main () {int n; while (scanf (% d, & n) {for (int I = 0; I