题目的意思就是:
x1=x-sqrt(y);
y1=y-sqrt(x);
这里我学会了用迭代法结二元二次方程组。
易知:x>x1&&y>y1 ,又把方程换成x=x1+sqrt(y),y=y1+sqrt(x);我们可以付初值x=x1,y=y1,将2试带入1试得x=x1+sqrt(y1+sqrt(x1));显然求得的x是要小于解值的,然后依次进行迭代,使得得到的x和y越来越接近解值,控制好精度就OK了,因为0 <= x, y <= 10000,所以只要迭代30次就差不多了,上代码
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
int t,tt;
double x,y,x1,y1;
scanf("%d",&t);
tt=t;
while (t--){
scanf("%lf%lf",&x1,&y1);
x=x1,y=y1;
for (int i=0;i<30;i++){
x=x1+sqrt(y);
y=y1+sqrt(x);
}
printf("Case %d: %.6lf %.6lf\n",tt-t,x,y);
}
return 0;
}