結果
問題 |
No.253 ロウソクの長さ
|
ユーザー |
|
提出日時 | 2015-07-24 23:36:26 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 736 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 23,040 KB |
実行使用メモリ | 25,604 KB |
平均クエリ数 | 29.81 |
最終ジャッジ日時 | 2024-07-16 05:02:45 |
合計ジャッジ時間 | 3,447 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 WA * 6 |
コンパイルメッセージ
main.cpp: In lambda function: main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%d",&f); | ~~~~~^~~~~~~~~
ソースコード
#include <cstdio> // cpp_binarysearch (C) @cielavenir under Boost Software License. // type F should be something like std::function<bool(T)>. template<typename T,typename F> T binarysearch(T lo,T hi,T eps,const F &checker){ int c=0; bool f=true; for(;lo+eps<hi;c++){ T mi=(lo+hi)/2; if(f)mi=10; f=false; int z=checker(mi); if(z==0)return mi+c; if(z==1)lo=mi-1,hi=hi-1; if(z==-1)hi=mi-1,lo=lo-1; if(lo<0)lo=0; if(hi<0)hi=0; } return lo+c+1; } template<typename T,typename F> T binarysearch(T lo,T hi,const F &checker){return binarysearch(lo,hi,1,checker);} int main(){ printf("! %d\n",binarysearch(1,1000000000,[&](int t){ printf("? %d\n",t); fflush(stdout); int f; scanf("%d",&f); return f; })); }