結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー Matsumoto Naoki
提出日時 2017-12-28 11:38:57
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 529 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 25,472 KB
実行使用メモリ 8,612 KB
最終ジャッジ日時 2025-03-03 11:07:20
合計ジャッジ時間 72,297 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:25: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘long int *’ [-Wformat=]
    8 |                 scanf("%d",&L[i]);
      |                        ~^  ~~~~~
      |                         |  |
      |                         |  long int *
      |                         int *
      |                        %ld
main.c:10:17: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘long int *’ [-Wformat=]
   10 |         scanf("%d",&K);
      |                ~^  ~~
      |                 |  |
      |                 |  long int *
      |                 int *
      |                %ld
main.c:11:9: warning: implicit declaration of function ‘solve’ [-Wimplicit-function-declaration]
   11 |         solve();
      |         ^~~~~
main.c: At top level:
main.c:25:6: warning: conflicting types for ‘solve’; have ‘void()’
   25 | void solve() {
      |      ^~~~~
main.c:11:9: note: previous implicit declaration of ‘solve’ with type ‘void()’
   11 |         solve();
      |         ^~~~~
main.c: In function ‘main’:
main.c:6:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d",&N);
      |         ^~~~~~~~~~~~~~
main.c:8:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |                 scanf("%d",&L[i]);
      |                 ^~~~~~~~~~~~~~~~~
main.c:10:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |         scanf("%d",&K);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
long int K;
unsigned int N;
long int L[10000000];
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&L[i]);
	}
	scanf("%d",&K);
	solve();
}
int C(double x){
	int num = 0;
	for(int i=0;i<N;i++){
		num += (int)(L[i] / x );
	}
	if(num >= K){
		return 1;
	}else{
		return 0;
	}
}

void solve() {
	double lb =0.0;
	double ub = 1000.0;
	double k = 2.0;
	double mid;
	for(int i =0; i<10000; i++){
		mid = (lb+ub)/k;
		if(C(mid) == 1){
			lb = mid;
		}else{
			ub = mid;
		}
	}
	printf("%1.15f\n",lb);
}
0