int main(){

	int t,i,n,sum,size,result,a[N];
	int *maxp,*minp;
	scanf("%d",&t);

	while(t--){
		scanf("%d",&n);
		sum=0;

		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
			sum+=a[i];
		}
		size=n;
		//maxp=&a[0];
		//minp=&a[0];
		maxp=(int*)malloc(sizeof(int));
		maxp=(int*)malloc(sizeof(int));
		findMaxMin(a,size,maxp,minp);
		if ((sum%n)==0)
			result=redistribute(a,size,maxp,minp);
		else
			result=-1;

		printf("%d",result);
	}
	return 0;
}
Esempio n. 2
0
void updateMinMaxTemperature()
{
	int16 *temp_high; 
	int16 *temp_low;
	uint8 id_low;
	uint8 id_high;
	uint8 num_low;
	uint8 num_high;
	
	
	// Find the minimum and maximum and update pointers and related variables
	findMaxMin(gCellTemp, &temp_low, &temp_high, &id_low, &id_high,
				&num_low, &num_high);
	

	// We update the values if we don't ignore these temperatures
	
	if(!ignoreThisTemperatureSensor(id_low,num_low)) // Lowest temperature
	{		
		gLowestCellTemp = temp_low;
		gLowestTempCellSlaveId = id_low;
		gLowestTempCellNum = num_low;
	}
	
	if(!ignoreThisTemperatureSensor(id_high,num_high)) // Highest temperature
	{
		gHighestCellTemp = temp_high;
		gHighestTempCellSlaveId = id_high;
		gHighestTempCellNum = num_high;
	}
		

}
Esempio n. 3
0
	Vector3f ColourConvertor::rgbToHsl(const Colour3f &rgb)
	{
		float max = 0.0f;
		float min = 0.0f;

		// clamp values -- remove for speedup
		float r = clamp(rgb.getR());
		float g = clamp(rgb.getG());
		float b = clamp(rgb.getB());

		// find max/min
		findMaxMin(r, g, b, max, min);

		float h = 0.0f;
		float s = 0.0f;
		float l = 0.0f;

		// L = (maxcolor + mincolor)/2 
		l = (max + min) / 2.0f;

		if(max == min)
		{
			h = 0.0f;
			s = 0.0f;
		}
		else
		{
			// If L < 0.5, S=(maxcolor-mincolor)/(maxcolor+mincolor)
			if(l <0.5f) s = (max - min) / (max + min);
			// If L >=0.5, S=(maxcolor-mincolor)/(2.0-maxcolor-mincolor)
			else if(l >= 0.5f) s = (max - min) / (2.0f - max - min);
		
			// If R=maxcolor, H = (G-B)/(maxcolor-mincolor)
			if(r == max) h = (g - b) / (max - min);
			// If G=maxcolor, H = 2.0 + (B-R)/(maxcolor-mincolor)
			else if(g == max) h = 2.0f + (b - r) / (max - min);
			// If B=maxcolor, H = 4.0 + (R-G)/(maxcolor-mincolor)
			else if(b == max) h = 4.0f + (r - g) / (max - min);
		}

		return Vector3f(h, s, l);
	}
int redistribute(int *a,int size,int *maxp,int *minp){

	int temp;
	temp=(*maxp-*minp);
	if (temp%2){
		*maxp-=((temp/2)+1);
		*minp+=((temp/2)+1);
	}
	else{
		*maxp-=(temp/2);
		*minp+=(temp/2);
	}	

	findMaxMin(a,size,maxp,minp);
	if(*maxp==*minp)
		return *maxp;
	else{	
		redistribute(a,size,maxp,minp);
	}
}
Esempio n. 5
0
void updateMinMaxVoltage()
{
	// Find the minimum and maximum and update pointers and related variables
	findMaxMin(gCellVolt, &gLowestCellVoltage,	&gHighestCellVoltage, &gLowestVoltageCellSlaveId, &gHighestVoltageCellSlaveId,
						&gLowestVoltageCellNum, &gHighestVoltageCellNum);
}
void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
                                       int64 numSamples,
                                       float& lowestLeft, float& highestLeft,
                                       float& lowestRight, float& highestRight)
{
    if (numSamples <= 0)
    {
        lowestLeft = 0;
        lowestRight = 0;
        highestLeft = 0;
        highestRight = 0;
        return;
    }

    const int bufferSize = (int) jmin (numSamples, (int64) 4096);
    MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);

    int* tempBuffer[3];
    tempBuffer[0] = (int*) tempSpace.getData();
    tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
    tempBuffer[2] = 0;

    if (usesFloatingPointData)
    {
        float lmin = 1.0e6f;
        float lmax = -lmin;
        float rmin = lmin;
        float rmax = lmax;

        while (numSamples > 0)
        {
            const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
            read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);

            numSamples -= numToDo;
            startSampleInFile += numToDo;

            float bufmin, bufmax;
            findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
            lmin = jmin (lmin, bufmin);
            lmax = jmax (lmax, bufmax);

            if (numChannels > 1)
            {
                findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
                rmin = jmin (rmin, bufmin);
                rmax = jmax (rmax, bufmax);
            }
        }

        if (numChannels <= 1)
        {
            rmax = lmax;
            rmin = lmin;
        }

        lowestLeft = lmin;
        highestLeft = lmax;
        lowestRight = rmin;
        highestRight = rmax;
    }
    else
    {
        int lmax = INT_MIN;
        int lmin = INT_MAX;
        int rmax = INT_MIN;
        int rmin = INT_MAX;

        while (numSamples > 0)
        {
            const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
            read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);

            numSamples -= numToDo;
            startSampleInFile += numToDo;

            for (int j = numChannels; --j >= 0;)
            {
                int bufMax = INT_MIN;
                int bufMin = INT_MAX;

                const int* const b = tempBuffer[j];

                for (int i = 0; i < numToDo; ++i)
                {
                    const int samp = b[i];

                    if (samp < bufMin)
                        bufMin = samp;

                    if (samp > bufMax)
                        bufMax = samp;
                }

                if (j == 0)
                {
                    lmax = jmax (lmax, bufMax);
                    lmin = jmin (lmin, bufMin);
                }
                else
                {
                    rmax = jmax (rmax, bufMax);
                    rmin = jmin (rmin, bufMin);
                }
            }
        }

        if (numChannels <= 1)
        {
            rmax = lmax;
            rmin = lmin;
        }

        lowestLeft = lmin / (float)INT_MAX;
        highestLeft = lmax / (float)INT_MAX;
        lowestRight = rmin / (float)INT_MAX;
        highestRight = rmax / (float)INT_MAX;
    }
}