数列极差。。。
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;
}这个是错的。。哪里不对。?
#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;
}这个是错的。。哪里不对。?
...全文
相关推荐
数列极差问题
在黑板上写n个正整数排成一个数列,进行如下操作:每次擦去其中两个数a和b,然后在数列中的加入一个数a×b+1,如此下去,直至黑板上剩下一个数,在所有按这种操作方式最后得到的数中,最大的数记做max,最小的数记做min,则该数列的极差定义为M=max-min。
算法分析与设计数列极差问题
算法分析与设计数列极差问题。还不错的程序,希望大家多多支持啊
vs2008下win32贪心法实现数列极差
利用贪心思想实现数列极差问题,visual stdio sp1下编译通过,并可运行。
算法-数列极差(信息学奥赛一本通-T1427).rar
算法-数列极差(信息学奥赛一本通-T1427).rar
max-min.rar_M?n_数列极差_数列极差问题
数列极差问题:给定n个正整数数列,进行如下操作:每次删去两个数 a和b,添加1个数 a*b+1,直到只剩1个数N。在所有的这样的N中,有1个最大Max的和最小的Min,M=Max-Min是极差,设计程序计算M。


