2022年7月21日 第一组 周鹏 两个正序数组的中位数寻找,做不出来,55555
今天做了一个比较简单右比较难得的算法。
我靠,什么人能只用一个循环就搞定啊,大家都是人,脑子别这么强好嘛!
题如下:

int []a = {1,3}; int m = a.length; int []b = {2,4}; int n = b.length; int []c = new int [m+n]; for (int i=0;i<m;i++){ c[i]=a[i]; } for (int i=m;i<m+n;i++){ c[i]=b[i-m]; } int p ; int q; for(int i=0;i<(c.length-1);i++){ q=c[i]; int v=0; for (int j =(i+1);j<c.length;j++){ if(c[i]>c[j]){ p=c[j]; c[j]=c[(i+1)+v]; c[(i+1)+v]=p; v++; } } int x = 0; x=c[i]; c[i]=c[i+v]; c[i+v]=x; if (c[i]!=q){ i--; } } double f = 0; if(c.length%2==0){ f=(double) (c[(c.length/2)-1]+c[c.length/2])/2; System.out.println((c[(c.length/2)-1]+c[c.length/2])); System.out.println(f); }else { f=c[(c.length-1)/2]; System.out.println(f); }
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号