結果
問題 | No.253 ロウソクの長さ |
ユーザー |
|
提出日時 | 2015-07-25 01:29:13 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 781 bytes |
コンパイル時間 | 243 ms |
コンパイル使用メモリ | 24,192 KB |
実行使用メモリ | 25,476 KB |
平均クエリ数 | 28.81 |
最終ジャッジ日時 | 2024-07-16 20:51:11 |
合計ジャッジ時間 | 2,829 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 36 |
コンパイルメッセージ
main.cpp: In function ‘int ask(int)’: main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d",&f); | ~~~~~^~~~~~~~~
ソースコード
#include <cstdio> #include <cstdlib> // 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){ for(int i=1;lo+eps<hi;i++){ T mi=(lo+hi)/2; int z=checker(mi-i); if(z==0)return mi; if(z==1)lo=mi+1; if(z==-1)hi=mi; } return lo; } template<typename T,typename F> T binarysearch(T lo,T hi,const F &checker){return binarysearch(lo,hi,1,checker);} int ask(int t){ printf("? %d\n",t); fflush(stdout); int f; scanf("%d",&f); return f; } __attribute__((noreturn)) void ans(int t){ printf("! %d\n",t); exit(0); } int main(){ if(ask(35)==-1)for(int i=1;;i++)if(ask(0)==0)ans(i); ans(binarysearch(10,1000000000,ask)); }