标签:style blog color io os ar for div art
这题挺有意思的,没想到规模大于3的slice的avg肯定要比它的子slice(小于3)的avg来得小的话,就不太好写。
1 int solution(vector<int> &A) { 2 // write your code in C++98 3 int minStart = 0; 4 double minAvg = (A[0]+A[1])/2.0; 5 int size = A.size(); 6 for(int i=0;i<size-1;i++) { 7 double tmpAvg = (A[i]+A[i+1])/2.0; 8 if(i<size-2&&A[i+2]<tmpAvg) { 9 tmpAvg = (A[i]+A[i+1]+A[i+2])/3.0; 10 } 11 if(tmpAvg<minAvg) { 12 minAvg = tmpAvg; 13 minStart = i; 14 } 15 } 16 return minStart; 17 }
标签:style blog color io os ar for div art
原文地址:http://www.cnblogs.com/cane/p/3973848.html