例题8-12(uva-12627)

#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
long long int  f(int k, int line) {
    
    
	if (line == 0) return 0;
	if (k == 0) return 1;

	int k2 = 1 << (k - 1);
	//每次横向扩展2倍 纵向扩展2倍
	// 
	if (line >= k2) return f(k - 1, line - k2) + pow(3,k-1) * 2ll;
	
	return 2 * f(k - 1, line);
}

int main() {
    
    
	int t, k, a, b, kase = 0;
	cin >> t;
	while (t--)
	{
    
    
		cin >> k >> a >> b;
		cout << "Case " << ++kase << ": " << f(k, b) - f(k, a - 1) << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/seanbill/article/details/115982240