結果

問題 No.3 ビットすごろく
ユーザー furafyfurafy
提出日時 2015-03-09 21:21:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,488 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 70,476 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-06 22:42:18
合計ジャッジ時間 1,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <math.h>

int count(int);
std::vector<int> duplog;

int main(void) {
	struct pibot{
		int masu = 1;
		int step_count = 1;
	}pib;
	int N, beki, a, num_of_bit, masu;
	std::queue<pibot> pattern;

	//std::cin >> N;
	N = 11;
	pattern.push(pib);
	while (pattern.size() >= 1) {
		if (N == 1)
			break;
		pib = pattern.front();
		pattern.pop();
		std::cout << pib.masu << std::endl;
		//ビット数を求める
		for (int i = 0; pib.masu > 2 * i; i++) {
			beki = i;
		}
		//1を数える
		num_of_bit = 0;
		a = pib.masu;
		while (beki >= 0) {
			if (a >= (int)pow(2, beki)) {
				a -= (int)pow(2, beki);
				num_of_bit++;
			}
			beki--;
		}
		//マスを進むor戻る
		if (num_of_bit > 0) {
			int masu = pib.masu;
			int add = masu + num_of_bit;
			int sub = masu - num_of_bit;
			pib.step_count++;
			std::cout << "numofbit:" << num_of_bit << std::endl;
			if (add == N) {
				pib.masu += num_of_bit;
				break;
			}
			if (sub == N) {
				pib.masu -= num_of_bit;
				break;
			}
			if (count(masu) < 1) {
				duplog.push_back(masu);
				if (add < N) {
					pib.masu = add;
					pattern.push(pib);
				}
				if (sub > 0) {
					pib.masu = sub;
					pattern.push(pib);
				}
			}
		}
	}
	if (pib.masu == N) {
		std::cout << pib.step_count << std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}

int count(int x) {
	for (int i = 0; i < duplog.size(); i++) {
		if (x == duplog[i])
			return 1;
	}
	return 0;
}
0