fty123456___ @ 2023-08-03 19:34:11
by ATZdhjeb @ 2023-08-03 19:39:56
题解:你好!
by yzm0325 @ 2023-08-03 19:41:40
@fty123456___ 参考题解的思路
by LEle0309 @ 2023-08-03 20:12:20
@fty123456___
核心代码:
double f(double x)
{
double y;
if(0<=x&&x<5)y=-x+2.5;
if(5<=x&&x<10)y=2-1.5*(x-3)*(x-3);
if(10<=x&&x<20)y=x/2-1.5;
return y;
}
模拟即可请勿抄袭
by LEle0309 @ 2023-08-03 20:14:08
违规紫衫
by 2041luyancheng @ 2023-08-14 15:56:47
像这种分段的题目,用if就好了
by 2024yejinghong @ 2023-08-21 16:07:42
#include<bits/stdc++.h>
using namespace std;
int main()
{
double x;
cin>>x;
if(x>=0&&x<5)
{
cout<<fixed<<setprecision(3)<< -x + 2.5;
}else{
if(x>=5&&x<10)
{
cout<<fixed<<setprecision(3)<<2-1.5*(x-3)*(x-3);
}else{
cout<<fixed<<setprecision(3)<<x/2-1.5;
}
}
return 0;
}
by 2024yejinghong @ 2023-08-21 16:08:51
完整代码