結果

問題 No.550 夏休みの思い出(1)
ユーザー mamekinmamekin
提出日時 2017-07-28 22:45:59
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,254 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 110,312 KB
実行使用メモリ 16,968 KB
最終ジャッジ日時 2024-10-10 03:49:52
合計ジャッジ時間 7,642 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 54
権限があれば一括ダウンロードができます

ソースコード

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