Thinking very ingenious a greedy topic, the overall principle is not win you I will try to drag your good horse into the water.
Title Address: Click to open the link
#include <cstdio> #include <algorithm> #include <iostream>using namespace std; int tj[1005],king[1005 ]; int n; Number of horses int main () {while (scanf ("%d", &n)!=eof) {for (int i = 0; I <n; i++) {scanf ("% D ", &tj[i]); } for (int j = 0; j<n; j + +) {scanf ("%d", &king[j]); } sort (tj,tj+n); Sort (king,king+n); int res = 0; int cnt = 0; int Tj_min,king_min,tj_max,king_max; tj_min = king_min = 0; Tj_max = King_max = n-1; while ((cnt++) <n) {if (Tj[tj_max]>king[king_max]) {res+=200; tj_max--; king_max--; } else if (Tj[tj_max]<king[king_max]) {res-=200; tj_min++; king_max--; } else {if (Tj[tj_min]>king[king_min]) {res+=200; tj_min++; king_min++; } else {if (Tj[tj_min]<king[king_max]) res-=200; tj_min++; king_max--; }}} printf ("%d\n", res); } return 0;}
Nanyang Tian Bogey Horse racing