結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー myanta
提出日時 2017-05-11 14:02:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 639 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 45,440 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-03-03 10:40:56
合計ジャッジ時間 5,233 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |                         scanf("%lld", &lt);
      |                         ~~~~~^~~~~~~~~~~~~
main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf("%lld", &k);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<vector>


using namespace std;
using ll=long long int;


int main(void)
{
	int i, j, n;
	ll k, sum;
	vector<long double> l;
	long double l_max, s, e, c, ans;

	while(scanf("%d", &n)==1)
	{
		l_max=0.0;
		l.resize(n);
		for(i=0;i<n;i++)
		{
			ll lt;
			scanf("%lld", &lt);
			l[i]=lt;
			if(l_max<l[i]) l_max=l[i];
		}
		scanf("%lld", &k);

		s=l_max/k;
		e=l_max;
		ans=s;
		for(j=0;j<100;j++)
		{
			if(e-s<0.0) break;
			c=(s+e)*0.5;
			sum=0;
			for(i=0;i<n;i++)
			{
				sum+=l[i]/c;
			}
			if(sum>=k)
			{
				ans=c;
				s=c;
			}
			else
			{
				e=c;
			}
		}
		printf("%.16Lf\n", ans);
	}

	return 0;
}
0