hdu 1052 贪心
// 判断出(田忌)的必胜局面和必败局面,则可以容易的得到决策方案
// 若没有明显的必胜局面和必败局面,则使用田忌赛马的策略
1 #include "bits/stdc++.h" 2 using namespace std; 3 int N; 4 int v1[1010], v2[1010]; 5 6 int main() 7 { 8 while(scanf("%d", &N) && N) { 9 int i, j; 10 for(i = 1; i <= N; ++i) { 11 scanf("%d", &v1[i]); 12 } 13 sort(v1 + 1, v1 + 1 + N); 14 for(j = 1; j <= N; ++j) { 15 scanf("%d", &v2[j]); 16 } 17 sort(v2 + 1, v2 + 1 + N); 18 19 int l1, r1, l2, r2; 20 l1 = l2 = 1; 21 r1 = r2 = N; 22 int win_time, lost_time; 23 win_time = lost_time = 0; 24 25 while(l1 <= r1) { 26 // printf("l1 == %d r1 == %d l2 == %d r2 == %d win_time == %d lost_time == %d\n", l1, r1, l2, r2, win_time, lost_time); 27 if(v1[l1] > v2[l2]) { 28 ++win_time; 29 ++l1; 30 ++l2; 31 continue; 32 } 33 if(v1[l1] < v2[l2]) { 34 ++lost_time; 35 ++l1; 36 --r2; 37 continue; 38 } 39 if(v1[r1] > v2[r2]) { 40 ++win_time; 41 --r1; 42 --r2; 43 continue; 44 } 45 if(v1[r1] < v2[r2]) { 46 ++lost_time; 47 ++l1; 48 --r2; 49 continue; 50 } 51 52 if(v1[l1] == v2[r2]) { 53 ++l1; 54 --r2; 55 continue; 56 } 57 if(v1[l1] < v2[r2]) { 58 ++lost_time; 59 ++l1; 60 --r2; 61 continue; 62 } 63 } 64 printf("%d\n", (win_time - lost_time) * 200); 65 } 66 }