萌新求助简单dfs
  • 板块学术版
  • 楼主打表大蒟蒻
  • 当前回复9
  • 已保存回复9
  • 发布时间2020/6/13 22:29
  • 上次更新2023/11/7 00:42:09
查看原帖
萌新求助简单dfs
181750
打表大蒟蒻楼主2020/6/13 22:29

#include <bits/stdc++.h>
using namespace std;
int n, l , r, cnt;
string dfs(int x) {
	if(x / 2 == 0 || x / 2 == 1) {
		int pos = x / 2;
		char sss = (pos + '0');
		string ss = "";
		char t = x % 2 + '0';
		ss += (sss + t + sss);
		return ss;
	}
	
	else {
		string t = dfs(x / 2);
		string ss = "";
		int pos2 = x % 2;
		char k = pos2 + '0';
		ss += t + k + t;
		return ss;
	}
}
int main () {
	//freopen("diff.in", "r", stdin);
	//freopen("diff.out", "w", stdout);
	cin >> n >> l >> r;
	/**
	string j = dfs(n);
	int pos3 = n % 2;
	char g = (n % 2 + '0');
	string s = "";
	s += (j + g + j);
	**/
	string s = dfs(n);
	//cout << s << '\n';
	for(int i = l; i <= r; i++)
		if(s[i] == '1') cnt++;
	cout << cnt << '\n';
	return 0;
} 

所以为什么挂了

2020/6/13 22:29
加载中...