老哥你这个好像有点问题,第一个测试用例输出是8哎。
这是我黑白鼠那道题代码,仅供参考:
//#include <iostream>
//using namespace std;
//
//struct mouse
//{
//	int first;
//	int second;
//	int third;
//};
//
//int GetDifference(int year, int k)
//{
//	mouse white = { 0 }, black = { 0 };
//	white.first = black.first = k;
//	for (int i = 0; i < year; ++i)
//	{
//		white.third = white.second;
//		int tmp = white.first;//k
//		white.first = white.first * 2 + white.second * 3;
//		white.second = tmp;
//
//		black.second = black.first;
//		black.first *= 3;
//	}
//	int value = white.first + white.second + white.third\
//		- black.first - black.second;
//	return value >= 0 ? value : (-value);
//}
//
//int main()
//{
//	int n, m;
//	//cin >> n>> m;
//	n = 3, m = 5;
//	int ret = GetDifference(n, m);
//	cout << ret << endl;
//	system("pause");
//	return 0;
//}