結果
| 問題 | No.68 よくある棒を切る問題 (2) |
| コンテスト | |
| ユーザー |
myanta
|
| 提出日時 | 2017-05-11 14:30:19 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 964 bytes |
| 記録 | |
| コンパイル時間 | 570 ms |
| コンパイル使用メモリ | 56,896 KB |
| 実行使用メモリ | 9,856 KB |
| 最終ジャッジ日時 | 2024-09-15 08:04:18 |
| 合計ジャッジ時間 | 14,253 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:72:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
72 | scanf("%d", <);
| ~~~~~^~~~~~~~~~~
main.cpp:76:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
76 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
main.cpp:79:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
79 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
ソースコード
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<utility>
using namespace std;
using ld=long double;
map<int,pair<ld,ld>,greater<int> > m;
vector<ld> l;
ld l_max;
ld solve(int k)
{
int sum;
ld s, e, c, ans;
int n=l.size(), i, j;
s=l_max/k;
e=l_max;
auto it=m.upper_bound(k);
if(m.find(k)!=m.end())
{
s=it->second.first;
e=it->second.second;
}
ans=s;
for(i=0;i<100;i++)
{
if(e-s<1e-10) break;
c=(s+e)*0.5;
sum=0;
for(j=0;j<n;j++)
{
sum+=l[j]/c;
}
if(sum>=k)
{
ans=c;
s=c;
m[sum]=make_pair(s, e);
}
else
{
e=c;
}
}
return ans;
}
int main(void)
{
int n, q, k, i;
ld ans;
while(scanf("%d", &n)==1)
{
m.clear();
l.resize(n);
l_max=0.0;
for(i=0;i<n;i++)
{
int lt;
scanf("%d", <);
l[i]=lt;
if(l_max<lt) l_max=lt;
}
scanf("%d", &q);
for(i=0;i<q;i++)
{
scanf("%d", &k);
ans=solve(k);
printf("%.12Lf\n", ans);
}
}
return 0;
}
myanta