ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

F. Maybe someone tell me. How I can done it problem without TL
Posted by Roma СЗШ№98 3 Mar 2007 18:10
#include <iostream>
using namespace std;
struct node
{
    int item;
    node *l;
    node *r;
    node():item(2),l(0),r(0){};
};
typedef node *link;
int sum;
void buildtree(link a,int k)
{
    int t = a->item;
    if(a->l == NULL)
    {
    a->l = new node;
    a->l->item = t+1;
    if(t+1 == k)sum++;
    if(t+1 > k)return;
    a->l->r = a->l->l = NULL;
    }
    else
        buildtree(a->l,k);
    if(a->r == NULL)
    {
    a->r = new node;
    a->r->item =t*2;
    if(t*2 == k)sum++;
    a->r->l = a->r->r = NULL;
    }
    else
        buildtree(a->r,k);


    buildtree(a->l,k);
    buildtree(a->r,k);
}
int main()
{
    link a = new node;
    int n,p;
    cin >> n >> p;
    buildtree(a,n);
    cout << sum%p;
    return 0;
}

Edited by author 03.03.2007 18:12
Re: F. Maybe someone tell me. How I can done it problem without TL
Posted by KIRILL(ArcSTU) 3 Mar 2007 18:19
DP
use array[1..10000000]
Re: F. Maybe someone tell me. How I can done it problem without TL
Posted by Roma СЗШ№98 3 Mar 2007 18:44
Damn!!! I had done it just think 5 minutes after your post. Why so unlucky day?:(