結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー hang_hang_cln
提出日時 2018-06-14 22:35:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 71,872 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-03-03 11:15:28
合計ジャッジ時間 4,627 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int countCuttedSticks(vector<int> sticks, double cutLength) {
    int count = 0;
    for (int stick: sticks) {
        count += (int)((double) stick / cutLength);
    }
    
    return count;
}

int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> sticks(N);
    for (int i=0; i < N; i++) {
        cin>>sticks[i];
    }
    long long K;
    cin>>K;
    
    double high, low, ans;
    high = (double)*max_element(sticks.begin(), sticks.end());
    low = 0.0;
    
    if (countCuttedSticks(sticks, high) == K)
        cout << high << endl;
    else {
        for(int i = 0; i < 100; i++) {
            ans = (high + low) / 2.0;
            if (countCuttedSticks(sticks, ans) >= K)
                low = ans;
            else
                high = ans;
        }
        cout<<fixed;
        cout << setprecision(10)<<ans<< endl;
    }
    return 0;
}
0