QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#168780#6542. Optimal Quadratic FunctionPhantomThreshold#WA 1102ms5948kbC++201.3kb2023-09-08 21:48:042023-09-08 21:48:05

Judging History

你现在查看的是最新测评结果

  • [2023-09-08 21:48:05]
  • 评测
  • 测评结果:WA
  • 用时:1102ms
  • 内存:5948kb
  • [2023-09-08 21:48:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long double db;
const int maxn=100000;
int n;
db x[maxn+50],y[maxn+50];

db gao(db A,db B,db C){
	db res=0;
	for (int i=1;i<=n;i++){
		db diff=A*x[i]*x[i]+B*x[i]+C-y[i];
		res=max(res,diff*diff);
	}
	return res;
}
db solveAB(db A,db B){
	db mn=1e18;
	db mx=-1e18;
	for (int i=1;i<=n;i++){
		db tmp=y[i]-A*x[i]*x[i]-B*x[i];
		mn=min(mn,tmp);
		mx=max(mx,tmp);
	}
	return (mx-mn)*(mx-mn)/4;
}

db solveA(db A){
	db l=-2e6,r=2e6;
	db ans=1e18;
	for (int cc=1;cc<=80;cc++){
		db mid1=(l+l+r)/3;
		db mid2=(l+r+r)/3;
		db res1=solveAB(A,mid1);
		db res2=solveAB(A,mid2);
		if (res1<res2){
			r=mid2;
			ans=min(ans,res1);
		}
		else{
			l=mid1;
			ans=min(ans,res2);
		}
	}
	return ans;
}

db solve(){
	db l=-2e6,r=2e6;
	db ans=1e18;
	for (int cc=1;cc<=80;cc++){
		db mid1=(l+l+r)/3;
		db mid2=(l+r+r)/3;
		db res1=solveA(mid1);
		db res2=solveA(mid2);
		if (res1<res2){
			r=mid2;
			ans=min(ans,res1);
		}
		else{
			l=mid1;
			ans=min(ans,res2);
		}
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	int T;
	cin >> T;
	for (;T--;){
		cin >> n;
		for (int i=1;i<=n;i++){
			int _x,_y;
			cin >> _x >> _y;
			x[i]=_x;
			y[i]=_y;
		}
		cout << fixed << setprecision(12) << solve() << "\n";
	}
	return 0;	
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5948kb

input:

1
4
0 0
1 3
2 9
3 0

output:

5.062500006772

result:

ok found '5.0625000', expected '5.0625000', error '0.0000000'

Test #2:

score: -100
Wrong Answer
time: 1102ms
memory: 5852kb

input:

60
1
1000 -990
2
171 -638
949 -99
2
633 227
-257 -602
3
634 -994
633 999
-374 995
3
445 -110
586 -121
462 29
9
-995 -224
-458 -833
691 -670
456 -259
-376 55
-563 -12
834 827
-826 -220
299 744
17
997 991
997 976
997 988
998 -986
999 -982
999 -980
999 -996
998 -988
998 -991
997 987
1000 996
999 -1000
...

output:

0.000000000000
1000000000000000000.000000000000
1000000000000000000.000000000000
1000000000000000000.000000000000
1000000000000000000.000000000000
1000000000000000000.000000000000
121.000000000000
1000000000000000000.000000000000
1000000000000000000.000000000000
248750.938443788719
15750.25000000730...

result:

wrong answer 2nd numbers differ - expected: '0.0000000', found: '1000000000000000000.0000000', error = '1000000000000000000.0000000'