結果

問題 No.550 夏休みの思い出(1)
ユーザー mamekinmamekin
提出日時 2017-07-28 22:45:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,254 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 108,724 KB
実行使用メモリ 17,088 KB
最終ジャッジ日時 2024-04-18 10:36:33
合計ジャッジ時間 7,443 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const double EPS = 1.0e-10;

void solveEquation(const vector<double>& a, vector<double>& x)
{
    class Func{
    public:
        static double f(const vector<double>& a, double x){
            double y = 0.0;
            for(int i=a.size()-1; i>=0; --i){
                y *= x;
                y += a[i];
            }
            return y;
        }
        static double findZero(const vector<double>& a, double x1, double x2){
            double y1 = f(a, x1);
            double y2 = f(a, x2);
            while(x1 < x2 - EPS){
                double x = (x1 + x2) / 2;
                double y = f(a, x);
                if((y1 < y2) ^ (y > 0))
                    x1 = x;
                else
                    x2 = x;
            }
            return (x1 + x2) / 2;
        }
    };

    x.clear();
    int n = a.size();
    if(n == 2){
        x.push_back(- a[0] / a[1]);
        return;
    }

    vector<double> b(n-1), x2; // 導関数の係数、極値点のx座標
    for(int i=0; i<n-1; ++i)
        b[i] = a[i+1] * (i+1);
    solveEquation(b, x2);

    const double LIMIT = 1.0e10;
    x2.insert(x2.begin(), -LIMIT);
    x2.push_back(LIMIT);

    for(unsigned i=0; i<x2.size()-1; ++i){
        double y1 = Func::f(a, x2[i]);
        double y2 = Func::f(a, x2[i+1]);
        if(abs(y2) < EPS){
            x.push_back(x2[i+1]);
            ++ i;
        }else if((y1 < 0) ^ (y2 < 0)){
            x.push_back(Func::findZero(a, x2[i], x2[i+1]));
        }
    }
}

int main()
{
    vector<double> a(4);
    a[3] = 1.0;
    for(int i=2; i>=0; --i)
        cin >> a[i];

    vector<double> x;
    solveEquation(a, x);

    vector<int> ans;
    for(int i=0; i<3; ++i)
        ans.push_back((int)round(x[i]));

    cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl;

    return 0;
}
0