int换long long试试
by wjmqwq @ 2019-08-11 21:10:48
话说int好像够了啊
by wjmqwq @ 2019-08-11 21:11:36
@[Dayspring](/space/show?uid=209903)
```
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct water{
int h,time;
}s[1000001];
bool cmp(water a,water b){
return a.time<b.time;
}
int main(){
double sum=0;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i].time;
s[i].h=i+1;
}
sort(s,s+n,cmp);
for(int i=0;i<n;i++){
sum+=s[i].time*(n-i-1);
cout<<s[i].h<<' ';
}
cout<<endl;
sum/=n;
printf("%.2lf\n",sum);
}
```
你用这个试试
by fzhfzh @ 2019-08-11 21:17:23
@[Dayspring](/space/show?uid=209903) 我知道你错哪了
~~(在浪费5次提交次数后)~~
你把sum也定义成double就行了
by fzhfzh @ 2019-08-11 21:26:43
@[fzhfzh](/space/show?uid=158050) 谢谢大佬。
by Dayspring @ 2019-08-12 19:10:23
十年OI一场空,不开 long long 见祖宗
by XianChanting @ 2019-12-01 10:08:04
@[fzhfzh](/user/158050) 为什么把sum改成double型就可以了,求教
by dor_yang @ 2020-02-19 18:58:31
@[杨朝晖](/user/309304) 精度问题。
by fzhfzh @ 2020-02-19 19:50:31
原来算的时候sum/n因为sum是int类型所以是下取整就有问题。
by fzhfzh @ 2020-02-19 19:51:57
10的6次方,int可能爆了
by Gym081030 @ 2021-11-29 21:16:53