수학 22번 1초짜리 풀이
게시글 주소: https://orbi.kr/00065243227
/**
* author: pizzaroot
* created: 2023-11-19 02:14:54
**/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
double f(double x, double b, double c, double d) {
return x * x * x + b * x * x + c * x + d;
}
double fprime(double x, double b, double c) {
return 3 * x * x + 2 * b * x + c;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
vector<pair<double, double>> cands;
for (double b = -10; b < 10; b += 0.02) {
for (double d = -10; d < 10; d += 0.02) {
double x = -1.0 / 4;
double c = -1.0 / 4 - 3 * x * x - 2 * b * x;
if (fprime(1.0 / 4, b, c) > 0.03) continue;
bool good = true;
for (int k = -50; k < 50; k++) {
if (f(k - 1, b, c, d) * f(k + 1, b, c, d) < -0.03) good = false;
}
if (good) {
cands.push_back({b, d});
}
}
}
for (auto &cd: cands) {
for (double b = cd.first - 2; b < cd.first + 2; b += 0.001) {
for (double d = cd.second - 2; d < cd.second + 2; d += 0.001) {
double x = -1.0 / 4;
double c = -1.0 / 4 - 3 * x * x - 2 * b * x;
if (fprime(1.0 / 4, b, c) > 0.0001) continue;
bool good = true;
for (int k = -5; k < 5; k++) {
if (f(k - 1, b, c, d) * f(k + 1, b, c, d) < -0.001) good = false;
}
if (good) {
cout << f(8, b, c, d) << '\n';
}
}
}
}
return 0;
}
1초만에 실행됨 ㄷㄷ
0 XDK (+0)
유익한 글을 읽었다면 작성자에게 XDK를 선물하세요.
^오^