数列极差。。。
http://acm.sdut.edu.cn/judgeonline/showproblem?problem_id=1894
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define MAX 99999999
bool cmp (const int a, const int b)
{
return a > b;
}
int main()
{
long n, i, a[50001], tempn, b[50001], min, max,num,t;
while (scanf("%d", &n)!=EOF)
{
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
b[i] = a[i];
}
tempn = n;
while (tempn > 1)
{
sort(a, a+n);
a[1] = a[0]*a[1]+1;
a[0] = MAX;
tempn--;
}
max = a[1];
tempn = n;
while (tempn > 1)
{
sort(b, b+n, cmp);
b[1] = b[0]*b[1]+1;
b[0] = 0;
tempn--;
}
min = b[1];
num=max-min;
t=1;
while(num/10)
{
t++;
num/=10;
}
printf("%d\n",t);
printf("%0.lf\n", fabs(max-min));
}
return 0;
}这个是错的。。哪里不对。?