12041 - BFS (Binary Fibonacci String)

All about problems in Volume 120. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
mostafa_angel
New poster
Posts: 23
Joined: Sun Oct 04, 2009 12:03 pm

12041 - BFS (Binary Fibonacci String)

Post by mostafa_angel » Mon Aug 08, 2011 6:35 pm

hi
I got RunTime Error...
as a general in the problem is mentioned that (j < 10001) so it means that we dont want to produce more than 10000 character for each BFS !
can anybody say that this is true !? or what's the problem of my code ? :-?

Code: Select all

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>


using namespace std;

string bfs[29];

void pr(int n , int a , int b)
{
	string s = bfs[n].substr(a , b-a+1);
	cout << s << endl;
}

int main()
{
	bfs[0] = "0";
	bfs[1] = "1";
	for(int i = 2 ; i < 29 ; i++)
	{
		bfs[i] = bfs[i-2] + bfs[i-1];
	}
	
	int t , n , a ,  b;
	scanf("%d",&t);
	for(int pp = 0 ; pp < t ; pp++)
	{
		scanf("%d %d %d",&n , &a , &b);
		if(n > 28)
		{
			if(n%2 == 0)
				pr(28 , a , b);
			else
				pr(27 , a , b);
		}
		else
		{
			pr(n , a , b);
		}
	}
	return 0;
}


Post Reply

Return to “Volume 120 (12000-12099)”