Tags » BF's

Πυρήνες και PPAs update 2

Το προηγούμενο update μπορείτε να το διαβάσετε εδώ. Αυτή είναι η τελευταία ενημέρωση (για τώρα), λόγω κάποιων αλλαγών που έκανα στα αποθετήρια. Παρακάτω παραθέτω την τρέχουσα κατάσταση των αποθετηρίων. 42 more words

Linux

Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root). 72 more words

Leetcode

Binary Tree Level Order Traversal

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).

For example:
Given binary tree… 20 more words

BFS

Maximum Depth of Binary Tree/Minimum Depth of Binary Tree

Maximum Depth of Binary Tree

  • Question
    Given a binary tree, find its maximum depth.
    The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

  • 446 more words
Leetcode

The Lost Tapes: Begging For Scraps Crew #01

Tom Burke and the BFS crew have hooked us up with some more old York Skateboarding videos…

This first Instalment features Tom Burke, Nathan Hazell, Brad Fillingham, Nick Eastburn and others from the BFS lads…

Video

SRM 664 (div2 medium)

Problem description here.

Problem summary
You are given three piles of stones each containing A, B and C (1 ≤ A,B,C ≤ 500) stones respectively. 328 more words

Topcoder

USACO: Mother's Milk

Problem Link : http://train.usaco.org/usacoprob2?a=tffkkLavmsp&S=milk3


/*
PROG: milk3
LANG: C++
 */

#include <bits/stdc++.h>

#define pii             pair <int,int>
#define sc              scanf
#define pf              printf
#define Pi              2*acos(0.0)
#define ms(a,b)         memset(a, b, sizeof(a))
#define pb(a)           push_back(a)
#define MP              make_pair
#define db              double
#define ll              long long
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define D(x)            cout<<#x " = "<<(x)<<endl
#define VI              vector <int>
#define DBG             pf("Hi\n")
#define MOD             100007
#define MAX             10000
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0)
#define SZ(a)           (int)a.size()
#define sf(a)           scanf("%d",&a)
#define sfl(a)          scanf("%lld",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sffl(a,b)       scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define loop(i,n)       for(int i=0;i<n;i++)
#define REP(i,a,b)      for(int i=a;i<b;i++)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
#define PRINT_CASE      printf("Case %d: ",z)
#define all(a)          a.begin(),a.end()
#define intlim          2147483648
#define inf             1000000
#define ull             unsigned long long

using namespace std;


/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/

struct data
{
    int a,b,c;
    data()
    {
        ;
    }
    data(int x, int y, int z)
    {
        a=x,b=y,c=z;
    }
};

int A,B,C;

bool ans;

bool visited;
int first=100;

void BFS(data x)
{
    map<data,bool>mp;
    queue<data>Q;
    visited=1;
    Q.push(x);
    while(!Q.empty())
    {
        data u=Q.front();
        Q.pop();
        if(u.a==0) ans=1,first=min(first,u.c);
        int bb=B-u.b,aa=A-u.a,cc=C-u.c;
        if(u.c)
        {
            data c2b=u,c2a=u;
            if(bb>=u.c)
            {
                c2b.b+=u.c;
                c2b.c=0;
            }
            else if(bb<u.c)
            {
                c2b.b=B;
                c2b.c-=bb;
            }

            if(aa>=u.c)
            {
                c2a.a+=u.c;
                c2a.c=0;
            }
            else if(aa<u.c)
            {
                c2a.a=A;
                c2a.c-=aa;
            }
            if(!visited)
            {
                Q.push(c2b);
                visited=1;
            }
            if(!visited)
            {
                Q.push(c2a);
                visited=1;
            }
        }

        if(u.b)
        {
            data b2a=u,b2c=u;
            if(aa>=u.b)
            {
                b2a.a+=u.b;
                b2a.b=0;
            }
            else
            {
                b2a.a=A;
                b2a.b-=aa;
            }
            if(cc>=u.b)
            {
                b2c.c+=u.b;
                b2c.b=0;
            }
            else
            {
                b2c.c=C;
                b2c.b-=cc;
            }
            if(!visited)
            {
                visited=1;
                Q.push(b2a);
            }
            if(!visited)
            {
                visited=1;
                Q.push(b2c);
            }
        }

        if(u.a)
        {
            data a2b=u,a2c=u;
            if(bb>=u.a)
            {
                a2b.b+=u.a;
                a2b.a=0;
            }
            else
            {
                a2b.b=B;
                a2b.a-=bb;
            }
            if(cc>=u.a)
            {
                a2c.c+=u.a;
                a2c.a=0;
            }
            else
            {
                a2c.c=C;
                a2c.c-=cc;
            }
            if(!visited)
            {
                visited=1;
                Q.push(a2c);
            }
            if(!visited)
            {
                visited=1;
                Q.push(a2b);
            }
        }

    }
}

int main()
{
    freopen("milk3.in","r",stdin);
    freopen("milk3.out","w",stdout);
    cin>>A>>B>>C;
    BFS(data(0,0,C));

    cout<<first;
    for(int i=first+1; i<=C; i++) if(ans[i]) cout<<" "<<i;
    cout<<endl;
    return 0;
} 116 more words
USACO