Tian Bogey horse race, roughly test instructions is Tian Bogey and King Horse racing, win a innings 200 yuan, lose a game lose 200 yuan, draw property does not move.
Enter an integer n, and the next line is the N horse of Tian Bogey, and the next line is the King's N horse. When n is 0 o'clock end. This is titled Greedy algorithm solution, there are two ideas. Thought two: 1, beginning is also the first sort, you can use sort quick row, 2, then the biggest horse and the king of the field to compare; 3, if Tian bogey the largest horse than the king, then on the Victory field ++;4, if the biggest Maxiau king, then will lose, so with Tian bogey the smallest horse to the king's largest horse; If the biggest horse of Tian bogey equals the king, then the smallest horse; 5. 1, if Tian bogey the smallest horse greater than the king, then win field ++;5. 2, if Tian bogey the smallest Maxiau king, then lose to the king; 5. 3, if Tian bogey the smallest horse is equal to the king, with Tian bogey the smallest horse to the king's biggest horse, if the King's largest horse, then the property to reduce 200;
Const intMax =1050; BOOLcmpintAintb) {returnA >b;} intPk2 () {intTian[max],king[max]; inti,j,n,m; while(Cin >>N) {if(n = =0) Break; for(i=1; i<=n; i++) {cin >>tian[i];} for(i=1; i<=n; i++) {cin >>king[i];} Sort (Tian+1, tian+1+n,cmp); Sort (King+1, king+1+n,cmp); intAns =0; intII,JJ; for(i=1, j=1, Ii=n, Jj=n; i<=II;) { if(Tian[i] > King[j]) {ans + = -; i++,j++; } Else if(Tian[i] < king[j]) {ans-= -; j++,ii--; } Else { if(Tian[ii] >KING[JJ]) {ans+= -; II--, jj--; } Else { if(Tian[ii] <King[j]) ans-= -; II--, J + +; } }} cout<< ans <<Endl; } return 0; }intMain () {PK2 (); return 0;}
Reference:
http://blog.163.com/zhaoyuan_sue/blog/static/20868323120125280842774/
POJ 2287 Field bogey horse racing greedy algorithm