Tian Ji's horse racing is a classic greedy, but it's hard to think of it. Every time you use the fastest and fastest, the slowest and the slowest to compare and judge
1) if Tian shortest is slower than Wang shortest, he will lose the game using the slowest comparison with Wang shortest. Otherwise, winning is of course the most cost-effective choice.
2) if Tian is slower than Wang, he will lose the game with the slowest comparison with Wang.
These two steps are greedy;
Also, pay attention to the situation ......
ViewCodeRight
#include
# include
int CMP (const void * a, const void * B) {return * (int *) A-* (int *) B;} int main () {int s [1001], t [1001], n; while (scanf ("% d", & n) = 1 & n! = 0) {for (INT I = 0; I
T [s2]) // compare the slowest horse, {sum1 ++; S1 ++; S2 ++;} else if (s [S1]
T [E2]) // compare the fastest horse {sum1 ++; E1 --; E2 --;} else if (s [E1]