結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー codershifthcodershifth
提出日時 2015-07-29 14:13:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 1,719 bytes
コンパイル時間 1,259 ms
コンパイル使用メモリ 162,280 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 23:26:46
合計ジャッジ時間 4,710 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 39 ms
6,944 KB
testcase_03 AC 75 ms
6,944 KB
testcase_04 AC 119 ms
6,944 KB
testcase_05 AC 120 ms
6,940 KB
testcase_06 AC 126 ms
6,944 KB
testcase_07 AC 103 ms
6,944 KB
testcase_08 AC 105 ms
6,940 KB
testcase_09 AC 102 ms
6,940 KB
testcase_10 AC 105 ms
6,940 KB
testcase_11 AC 112 ms
6,940 KB
testcase_12 AC 108 ms
6,944 KB
testcase_13 AC 93 ms
6,940 KB
testcase_14 AC 98 ms
6,944 KB
testcase_15 AC 89 ms
6,940 KB
testcase_16 AC 106 ms
6,940 KB
testcase_17 AC 86 ms
6,944 KB
testcase_18 AC 72 ms
6,944 KB
testcase_19 AC 92 ms
6,940 KB
testcase_20 AC 75 ms
6,944 KB
testcase_21 AC 74 ms
6,940 KB
testcase_22 AC 65 ms
6,940 KB
testcase_23 AC 67 ms
6,944 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 17 ms
6,944 KB
testcase_29 AC 9 ms
6,944 KB
testcase_30 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class CuttingStick1 {
public:
    void solve(void) {
            int N;
            cin>>N;
            vector<double> L(N);
            REP(i,N)
                cin>>L[i];
            ll K;
            cin>>K;
            // ある長さ D の棒を K 本つくれるならそれ以下の長さの棒も作れる (D をさらに分割すればよい)
            // よって二分探索すればよい

            double high = 1E+9;
            double low  = 1e-9;

            REP(_, 100)
            {
                if (abs(high-low) < 1e-9)
                    break;
                double mid = (high+low)*0.5;
                auto tmp = L;

                ll     k = 0;
                size_t i = 0;
                while (i < tmp.size())
                {
                    if (k >= K)
                        break;
                    if (tmp[i] < mid)
                        ++i;
                    else if (tmp[i] >= mid)
                    {
                        ll kk = tmp[i]/mid;
                        tmp[i] -= kk*mid;
                        k += kk;
                    }
                }
                if (k >= K)
                    low = mid;
                else
                    high = mid;
            }
            cout<<setprecision(20)<<low<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new CuttingStick1();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0