Tags » BF's

Chapter 12 - Part 3

The long, narrow road went on, sitting between acres of green land. Kirk drove his car down the road and sitting next to him in the passenger’s seat was Henry, who looked onward out the window. 1,712 more words

Brave Fighting Sun

01 Matrix

Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.

The distance between two adjacent cells is 1. 385 more words

Chapter 11 - Part 2

The glow of the moon above reflected on the ocean below. It was a quiet night when Belkley arrived before him, the man he once knew ten years ago. 1,048 more words

Brave Fighting Sun

Chapter 10 - Part 2

Law’s pursuit of Wihll carried him near the edge of Rezar, where many of the properties had been abandoned. Multiple condemned buildings lined the streets and not a single person was to be found. 1,807 more words

Brave Fighting Sun

UVA 439: Knight Moves

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <queue>

using namespace std;

int movx[]={-2,-2,-1,-1,1,1,2,2};
int movy[]={1,-1,-2,2,2,-2,1,-1};
int counts;

int main()
{
    int i,i1,i2,x1,x2,subx,suby;
    string s1,s2;
    
    while (cin>>s1>>s2)
    {
        i1=s1[0]-'a'+1;
        x1=s1[1]-'0';
        
        i2=s2[0]-'a'+1;
        x2=s2[1]-'0';
        
        memset(counts,-1,sizeof(counts));
        pair<int,int>p;
        p.first=i1;p.second=x1;
        counts=0;
    
        queue<pair<int,int>>q;
        q.push(p);
        
        while(!q.empty())
        {
            p=q.front();
            q.pop();
        
            if (p.first==i2 && p.second==x2) break;
       
            for (i=0;i<8;i++)
            {
                subx=p.first+movx[i];
                suby=p.second+movy[i];
            
        
                if ((subx>=1 && subx<=8)&&(suby>=1 && suby<=8))
                {
                    if (counts!=-1) continue;
                    counts=1+counts;
                    q.push(make_pair(subx,suby));
                }
            }
        }
        
        cout<<"To get from "<<s1<<" to "<<s2<<" takes "<<counts<<" knight moves.\n";
    }
    
    return 0;
} 12 more words
Graphs

UVA 10608: Friends

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef vector <int> ve;
typedef vector <ve> vve;
typedef vector <bool> vi;


int main() {
    
    int n,m,t,i,u,v,res,tmp;
    
    cin>>t;
    
    while (t--)
    {
        cin>>n>>m;
        vve G(n+1);
        while (m--)
        {
            cin>>u>>v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        
        res=0;
        vi known(n+1,false);
        
        for (i=1;i<=n;i++)
        {
            if (known[i]) continue;
            tmp = 0;
            queue<int>q;
            q.push(i);
            
            while (!q.empty())
            {
                u=q.front();
                q.pop();
                if (known[u]) continue;
                tmp++;
                known[u]=true;
                
                for (i=0;i<G[u].size();i++)
                {
                    v=G[u][i];
                    if (known[v]) continue;
                    q.push(v);
                }
            }
            res=max(res,tmp);
        }
        cout<<res<<endl;
    }
    
    return 0;
}
Graphs

UVA 10651: Pebble Solitaire

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <map>
#include <string>


using namespace std;

int n;
string s,top;


int main() {
    
    int t,i,j,minimo,counter;
    bool games;
    
    scanf("%d",&t);
    
    while (t--)
    {
        cin>>s;
        map<string,int>m;
        map<string,bool>known;
        counter=0;
        for (i=0;i<s.size();i++)
            if (s[i]=='o')
                counter++;
        m[s]=counter;
        known[s]=false;
        
        queue<string>q;
        q.push(s);
        minimo=9999999;
        while (!q.empty())
        {
            top=q.front();
            q.pop();
            if (known) continue;
            known=true;
            j=m;
            games=false;
            for (i=0;i<top.size();i++)
            {
                if (top[i]=='o' && top=='o')
                {
                    if (i>=1)
                    {
                        if (top=='-')
                        {
                            games=true;
                            top[i]='-';
                            top='-';
                            top='o';
                            m=j-1;
                            q.push(top);
                            top[i]='o';
                            top='o';
                            top='-';
                        }
                    }
                    
                    if (i<10)
                    {
                        if (top=='-')
                        {
                            games=true;
                            top[i]='-';
                            top='-';
                            top='o';
                            m=j-1;
                            q.push(top);
                            top[i]='o';
                            top='o';
                            top='-';
                        }
                    }
                }
            }
            
            if (!games)
                minimo=min(minimo,j);

        }
        printf("%d\n",minimo);
    }  
    return 0;
} 16 more words
Graphs