1 private static List<int> GetXList(int value) 2 { 3 List<int> xList=new List<int>(); 4 //将数据粗略分为10-20段,在此区间内寻找余数最小的值 5 float minResidueRatio=1.01f;//余数 6 int goalElement=0; 7 for(int i=10;i<=20;i++) 8 { 9 int element=value/i; 10 element=GetXSpace(element); 11 if(value%element==0) 12 { 13 goalElement=element; 14 break; 15 } 16 float residueRatio=(float)((value/element+1)*element-value)/(float)element; 17 if(residueRatio<minResidueRatio) 18 { 19 minResidueRatio=residueRatio; 20 goalElement=element; 21 } 22 } 23 int segNum=0;//分段数 24 if(value%goalElement==0) 25 segNum=value/goalElement; 26 else 27 segNum=value/goalElement+1; 28 for(int i=0;i<=segNum;i++) 29 { 30 xList.Add(i*goalElement); 31 } 32 return xList; 33 34 } 35 36 private static int GetXSpace(int value) 37 { 38 int Digit=GetNumDigit(value); 39 int num=(int)Math.Pow(10,Digit); 40 int []arr={1,2,5}; 41 int goal=num; 42 for(int i=0;i<arr.Length;i++) 43 { 44 if(num*arr[i]<=value) 45 { 46 goal=num*arr[i]; 47 } 48 else 49 { 50 break; 51 } 52 53 } 54 return goal; 55 } 56 57 private static int GetNumDigit(int num) 58 { 59 int temp=10; 60 int count=0; 61 while(temp<num) 62 { 63 temp*=10; 64 count++; 65 } 66 return count; 67 }