結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー Bucchiman
提出日時 2020-08-19 16:40:16
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 26,880 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-03-03 11:43:41
合計ジャッジ時間 2,888 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:27:11: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |     int N;scanf("%d", &N);
      |           ^~~~~~~~~~~~~~~
main.c:29:27: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     for(int i=0; i<N; i++)scanf("%lf", L+i);
      |                           ^~~~~~~~~~~~~~~~~
main.c:30:16: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     long int K;scanf("%ld", &K);
      |                ^~~~~~~~~~~~~~~~

ソースコード

diff #

/*
 * FileName:     code
 * CreatedDate:  2020-08-19 16:15:34 +0900
 * LastModified: 2020-08-19 16:40:02 +0900
 */

#include <stdio.h>
#include <stdlib.h>
#define l_max 1e9
#define error 1e-9

int C(double *L, int N, long int K, double middle){
    long int num = 0;
    for(int i=0; i<N; i++){
        num += (long int)(L[i]/middle);
    }
    if(K>num){
        return 1;
    }
    else{
        return 0;
    }
}


int main(void){
    int N;scanf("%d", &N);
    double *L = malloc(N*sizeof(double));
    for(int i=0; i<N; i++)scanf("%lf", L+i);
    long int K;scanf("%ld", &K);
    double left = 0, right = l_max, middle;
    for(int i=0; i<100; i++){
//        double left = 0, right = l_max;
        middle = (left + right)/2;
        if(C(L, N, K, middle)){
            right = middle;
        }
        else{
            left = middle;
        }
    }
    printf("%lf\n", middle);
    return 0;
}
0