贪心,没完全理解啊,明天再想想,今天已经想了一天了,唉
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 const int maxn=1000+10; 6 int tian[maxn],qi[maxn]; 7 int main() 8 { 9 int n; 10 while(scanf("%d",&n)&&n) 11 { 12 int i,j; 13 for(i=1;i<=n;i++) scanf("%d",&tian[i]); 14 for(i=1;i<=n;i++) scanf("%d",&qi[i]); 15 sort(tian+1,tian+n+1); 16 sort(qi+1,qi+n+1); 17 int front1=1,rear1=n,front2=1,rear2=n; 18 int ans=0; 19 while(front1<=rear1) 20 { 21 if(tian[front1]<qi[front2]) 22 { 23 ans-=200; 24 front1++; 25 rear2--; 26 } 27 else if(tian[front1]>qi[front2]) 28 { 29 ans+=200; 30 front1++; 31 front2++; 32 } 33 else 34 { 35 if(tian[rear1]<=qi[rear2]) 36 { 37 if(tian[front1]<qi[rear2]) ans-=200; 38 front1++; 39 rear2--; 40 } 41 else 42 { 43 rear1--; 44 rear2--; 45 ans+=200; 46 } 47 } 48 } 49 printf("%d\n",ans); 50 } 51 return 0; 52 }