結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー myantamyanta
提出日時 2017-05-11 14:02:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 639 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 39,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 23:50:05
合計ジャッジ時間 5,360 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 60 ms
6,940 KB
testcase_03 AC 113 ms
6,944 KB
testcase_04 AC 153 ms
6,940 KB
testcase_05 AC 155 ms
6,944 KB
testcase_06 AC 153 ms
6,944 KB
testcase_07 AC 154 ms
6,944 KB
testcase_08 AC 156 ms
6,940 KB
testcase_09 AC 157 ms
6,944 KB
testcase_10 AC 139 ms
6,940 KB
testcase_11 AC 145 ms
6,940 KB
testcase_12 AC 133 ms
6,940 KB
testcase_13 AC 142 ms
6,940 KB
testcase_14 AC 148 ms
6,944 KB
testcase_15 AC 132 ms
6,944 KB
testcase_16 AC 152 ms
6,940 KB
testcase_17 AC 155 ms
6,940 KB
testcase_18 AC 153 ms
6,940 KB
testcase_19 AC 157 ms
6,948 KB
testcase_20 AC 155 ms
6,940 KB
testcase_21 AC 155 ms
6,940 KB
testcase_22 AC 138 ms
6,940 KB
testcase_23 AC 145 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 4 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 26 ms
6,940 KB
testcase_29 AC 14 ms
6,944 KB
testcase_30 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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