3 条题解
-
1
上代码:
1.普通
#include<bits/stdc++.h> using namespace std; int main(){ double x; cin>>x; cout << fixed << setprecision(3); if(x<5) cout << (-x)+2.5; else if(x<10) cout << 2.0-1.5*(x-3)*(x-3); else cout << x/2-1.5; return 0; }2.函数
#include<bits/stdc++.h> using namespace std; double f(double x){ if(x<5) return (-x)+2.5; else if(x<10) return 2.0-1.5*(x-3)*(x-3); else return x/2-1.5; } int main(){ double x; cin>>x; cout << fixed << setprecision(3)<<f(x); return 0; }3.傻瓜式
#include<bits/stdc++.h> using namespace std; #include<bits/stdc++.h> using namespace std; int main(){ double x; cin >> x; const double eps = 1e-9; if (abs(x - 0.0) < eps) cout << fixed << setprecision(3) << 2.500 << endl; else if (abs(x - 1.0) < eps) cout << fixed << setprecision(3) << 1.500 << endl; else if (abs(x - 2.0) < eps) cout << fixed << setprecision(3) << 0.500 << endl; else if (abs(x - 3.0) < eps) cout << fixed << setprecision(3) << -0.500 << endl; else if (abs(x - 4.0) < eps) cout << fixed << setprecision(3) << -1.500 << endl; else if (abs(x - 5.0) < eps) cout << fixed << setprecision(3) << -4.000 << endl; else if (abs(x - 6.0) < eps) cout << fixed << setprecision(3) << -11.500 << endl; else if (abs(x - 7.0) < eps) cout << fixed << setprecision(3) << -22.000 << endl; else if (abs(x - 8.0) < eps) cout << fixed << setprecision(3) << -35.500 << endl; else if (abs(x - 9.0) < eps) cout << fixed << setprecision(3) << -52.000 << endl; else if (abs(x - 10.0) < eps) cout << fixed << setprecision(3) << 3.500 << endl; else if (abs(x - 11.0) < eps) cout << fixed << setprecision(3) << 4.000 << endl; else if (abs(x - 12.0) < eps) cout << fixed << setprecision(3) << 4.500 << endl; else if (abs(x - 13.0) < eps) cout << fixed << setprecision(3) << 5.000 << endl; else if (abs(x - 14.0) < eps) cout << fixed << setprecision(3) << 5.500 << endl; else if (abs(x - 15.0) < eps) cout << fixed << setprecision(3) << 6.000 << endl; else if (abs(x - 16.0) < eps) cout << fixed << setprecision(3) << 6.500 << endl; else if (abs(x - 17.0) < eps) cout << fixed << setprecision(3) << 7.000 << endl; else if (abs(x - 18.0) < eps) cout << fixed << setprecision(3) << 7.500 << endl; else if (abs(x - 19.0) < eps) cout << fixed << setprecision(3) << 8.000 << endl; else { double y; if (x >= 0 && x < 5) { y = -x + 2.5; } else if (x >= 5 && x < 10) { y = 2 - 1.5 * (x - 3) * (x - 3); } else if (x >= 10 && x < 20) { y = x / 2 - 1.5; } cout << fixed << setprecision(3) << y << endl; } return 0; }
信息
- ID
- 4497
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- (无)
- 递交数
- 125
- 已通过
- 81
- 上传者