数列极差。。。

xuke535010084 2011-05-20 11:10:56
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;
}这个是错的。。哪里不对。?
...全文
149 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

64,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧