MMM24's blog

By MMM24, history, 9 years ago, In English

Hi all. I have the following code

void f(int x)
{
  if(x<0||x>10000) return ;
  f(x-1);
  f(2*x);
}

When this code is executed it will start from left (x-1) untill he reach the last element and then go to the right and so on

How ever i want it to proceed from up to down like in the picture

Any helps. regards.

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it

By MMM24, history, 9 years ago, In English
How to create a Matrix indexed by strings ex( m["abc"]["xyz"]=1 ) .
I google about it and all i can find is array indexed by string .

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By MMM24, history, 9 years ago, In English

This the problem statement http://poj.org/problem?id=1308 The problem statement give a graph constructed by given each connected nodes and you have to determine if it's a tree or note

first and second are tree and the third is not .

My solution was to find first the root wich should be unique using set otherwise it's not a tree .

while(cin >> a >> b)
{
 graph[a][b]=1;
 s.insert(a);
 if(s.count(b)) s.erase(b);
}

if(s.size()!=1) cout << "Case "<<z<<" is not a tree." << endl ;

once we have found the root i preform a dfs starting from the root .

dfs(root);
void dfs(int x)
{
    visit[x]++;
	if(visitv[x]>2)return;
	int i;
	for(i=0;i<1010;i++)if(graph[x][i])dfs(i);
}

each visited node will be incrimented by 1 . after dfs i check the number of times each node is visited , if it's visited more than one time than the given graph is not a tree otherwise it should be a tree . Any body can tell why this got a WA ? thanks.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By MMM24, history, 9 years ago, In English

Hi all. i was thinking about this problem : we have a person located at the origin of plane and we are given a point wich is the destination also we are given a number of lake , each lake is defined by a center and a radius . wich is the minimum distance needed to go from the origin to the distination . i managed to solve the points of intersection between the line formed by the 2 points and the circles however i'am asking how can i calculate the distance arround it ?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it