6 solutions
-
6
非打表,点赞!!!!!!!👀️
#include<bits/stdc++.h> using namespace std;//binary_search double f(double x){ return x*x*x*x*x-15*x*x*x*x+85*x*x*x-225*x*x+274*x-121; } int main(){ double r=2.4,l=1.5,mid=(l+r)/2; while(r-l>double(1e-10)){ mid=(r+l)/2; if(f(mid)*f(r)<0) l=mid; if(f(mid)*f(l)<0) r=mid; } printf("%.6f",mid); return 0; }
-
4
题意
找在 的根
根:, 就是根
思路
由于有超精确的小数,所以要用 eps
二分找就行了
代码
#include <bits/stdc++.h> #define f(x) (x * x * x * x * x - 15 * x * x * x * x + 85 * x * x * x - 225 * x * x + 274 * x - 121) using namespace std; const double eps = 1e-8; int main(int argc, char **argv){ double l = 1.5,r = 2.4; double mid = (l + r) / 2; while (r - l > eps){ // 如果 l 与 r 相差几乎等于 0 mid = (l + r) / 2; double x = f(mid) * f(l); if (x < 0) r = mid; // 如果根在左区间 else if(x > 0) l = mid; // 如果根在右区间 } printf("%.6f",mid); return 0; }
-
0
#include<cstdio> #include<cmath> #define eps 1e-10 inline double f(double x) { return pow(x,5)-15*pow(x,4)+85*pow(x,3)-225*pow(x,2)+274*x-121; } double l=1.5,r=2.4,mid,res; int main() { while(fabs(l-r)>eps) //实数判等是比较他们的差值是否小于eps { mid=l+(r-l)/2; res=f(mid); if(fabs(res)<eps) { printf("%.6lf",mid); return 0; } else if(res<eps) r=mid; else l=mid; } return 0; }
-
-4
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int a[maxn];
int main(){
int n,m; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; cin>>m; sort(a,a+n);
{ for(int i=0;i<n;i++){ int liu=m-a[i]; if(binary_search(a+i+1,a+n,liu)){ cout<<a[i]<<" "<<liu; return 0;
}
} cout << "No" << endl; } }
-
-4
- 1
Information
- ID
- 726
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 148
- Accepted
- 43
- Uploaded By