精度误差
查看原帖
精度误差
831011
Deltary_楼主2023/3/11 21:41

这辈子最讨厌的事就是精度误差了

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define Endl endl
using namespace std;
typedef long long ll;
const char sp=' ';
/*I love CCF,lg,kkk,cz,pinkrabbit,IOI,
  So let me get AC,plz.*/
struct homo{
	int t,l;//t时间,l顺序
}h[1145];
bool cmp(homo a,homo b){
	return a.t<b.t;
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i].t;
		h[i].l=i;
	}
	sort(h+1,h+n+1,cmp);
	for(int i=1;i<=n;i++){
		cout<<h[i].l<<sp;
	}
	cout<<endl;
	int ansTime=0;
	for(int i=1;i<=n;i++){
		ansTime+=i*h[n-i].t;
	}
	printf("%.2f",ansTime*1.0/n);
	return 0;
}
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define Endl endl
using namespace std;
typedef long long ll;
const char sp=' ';
/*I love CCF,lg,kkk,cz,pinkrabbit,IOI,
  So let me get AC,plz.*/
struct homo{
	int t,l;//t时间,l顺序
}h[1145];
bool cmp(homo a,homo b){
	return a.t<b.t;
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i].t;
		h[i].l=i;
	}
	sort(h+1,h+n+1,cmp);
	for(int i=1;i<=n;i++){
		cout<<h[i].l<<sp;
	}
	cout<<endl;
	double ansTime=0;
	for(int i=1;i<=n;i++){
		ansTime+=i*h[n-i].t;
	}
	printf("%.2f",ansTime*1.0/n);
	return 0;
}

ansTime(总时间和)开 int 82pts

double AC

求助原因,以及避免误差的方法

2023/3/11 21:41
加载中...