题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805466364755968 题目思路:这道题思路不难,一开始就想到two pointers,两个数组同时进行将小的放回去;但是这样内存会不够,另外虽然题目说用 long int但是实际用int就行不然内存更不高;我们让s2不读入只进行比较这样就可以缩减内存了; 有一个小坑点,要设置n[s]值为极大值,不然因为n[s]为负数会把这个加进去; 代码:
# include<cstdio> # include<math.h> int main(){ int n1[200020]; int s1,s2,i,j,k=0,temp,count; scanf("%d",&s1); for( i=1;i<=s1;i++) scanf("%d",&n1[i]); n1[i]=99999999; scanf("%d",&s2); if((s1+s2)%2==1) count=(s1+s2)/2+1; else count=((s1+s2)/2); i=1; for(j=1;j<=s2;j++){ scanf("%d",&temp); while(n1[i]<=temp){ k++; if(k==count){ printf("%d",n1[i]); } i++; } k++; if(k==count){ printf("%d",temp); } } while(i<=s1){ k++; if(k==count){ printf("%d",n1[i]); } i++; } return 0; }