結果

問題 No.246 質問と回答
ユーザー KlayKlay
提出日時 2017-05-01 18:43:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,272 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 51,924 KB
実行使用メモリ 24,288 KB
平均クエリ数 30.90
最終ジャッジ日時 2023-09-23 20:22:49
合計ジャッジ時間 3,481 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
24,072 KB
testcase_01 AC 42 ms
23,268 KB
testcase_02 AC 43 ms
23,904 KB
testcase_03 AC 43 ms
24,048 KB
testcase_04 AC 42 ms
23,556 KB
testcase_05 AC 43 ms
23,868 KB
testcase_06 AC 43 ms
23,688 KB
testcase_07 AC 42 ms
23,268 KB
testcase_08 AC 42 ms
23,400 KB
testcase_09 AC 42 ms
23,856 KB
testcase_10 AC 42 ms
23,556 KB
testcase_11 AC 41 ms
24,288 KB
testcase_12 AC 42 ms
23,532 KB
testcase_13 AC 42 ms
23,568 KB
testcase_14 AC 41 ms
23,436 KB
testcase_15 AC 41 ms
23,868 KB
testcase_16 AC 41 ms
23,904 KB
testcase_17 AC 42 ms
23,532 KB
testcase_18 AC 40 ms
23,520 KB
testcase_19 AC 41 ms
24,120 KB
testcase_20 AC 42 ms
23,400 KB
testcase_21 AC 42 ms
24,072 KB
testcase_22 AC 42 ms
24,276 KB
testcase_23 AC 42 ms
23,436 KB
testcase_24 AC 42 ms
23,424 KB
testcase_25 AC 42 ms
24,060 KB
testcase_26 AC 42 ms
23,856 KB
testcase_27 AC 43 ms
23,880 KB
testcase_28 AC 42 ms
24,036 KB
testcase_29 AC 42 ms
23,292 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘REALM getRealm(REALM, bool)’:
main.cpp:45:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include <iostream>

#define questionMAX 100

/*
answer = true  := 以上
answer = false := 未満
*/

class REALM
{
	public:
	
	unsigned long long N_MAX, N_MIN, N_MEAN;
	
	void getMean(void)
	{
		N_MEAN = (N_MAX + N_MIN) / 2;
	}
};

bool question(int x)
{
	bool answer;
	
	std::cout << "? " << x << std::endl;
	
	std::cin >> answer;
	
	if(answer)
	{
		return true;
	}
	else
	{
		return false;
	}
}

REALM getRealm(REALM realm_prev, bool answer)
{
	REALM realm_next;
	
	
}

int main(void)
{
	REALM realm;
	realm.N_MAX = 1000000000;
	realm.N_MIN = 1;
	realm.getMean();
	
	for(int i = 0; i < questionMAX; i ++)
	{
		if(question(realm.N_MEAN))
		{
			realm.N_MIN = realm.N_MEAN;
			realm.getMean();
		}
		else
		{
			realm.N_MAX = realm.N_MEAN - 1;
			realm.getMean();
		}
		
		if(realm.N_MAX == realm.N_MIN)
		{
			std::cout << "! " << realm.N_MAX << std::endl << std::flush;
			break;
		}
		else if(realm.N_MIN == realm.N_MAX - 1)
		{
			if(question(realm.N_MAX))
			{
				std::cout << "! " << realm.N_MAX << std::endl << std::flush;
				break;
			}
			else
			{
				std::cout << "! " << realm.N_MIN << std::endl << std::flush;
				break;
			}
		}
		
		//for debug
		//std::cout << realm.N_MIN << " <= x <= " << realm.N_MAX << std::endl;
	}

	return 0;
}


















0