hiho week 99 register

Ended

Participants:253

Verdict:Accepted
Score:100 / 100
Submitted:2016-05-21 22:16:29

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <queue>
#include <vector>
#include <string>
using namespace std;
bool valid(int i,int j)
{
    return i>=0&&i<=7&&j>=0&&j<=7;
}
void bfs(vector<vector<int>>&chess,int i,int j)
{
    queue<pair<int,int>> q;
    q.push(make_pair(i,j));
    int count=0;
    while(!q.empty())
    {
        int size=q.size();
        for (int k=0;k<size;k++)
        {
            pair<int,int> cur=q.front();q.pop();
            int x=cur.first,y=cur.second;
            chess[x][y]=count;
            if(valid(x-2,y-1)&&chess[x-2][y-1]==-1)  q.push(make_pair(x-2,y-1));
            if(valid(x-2,y+1)&&chess[x-2][y+1]==-1)  q.push(make_pair(x-2,y+1));
            if(valid(x-1,y+2)&&chess[x-1][y+2]==-1)  q.push(make_pair(x-1,y+2));
            if(valid(x+1,y+2)&&chess[x+1][y+2]==-1)  q.push(make_pair(x+1,y+2));
            if(valid(x+2,y+1)&&chess[x+2][y+1]==-1)  q.push(make_pair(x+2,y+1));
            if(valid(x+2,y-1)&&chess[x+2][y-1]==-1)  q.push(make_pair(x+2,y-1));
            if(valid(x+1,y-2)&&chess[x+1][y-2]==-1)  q.push(make_pair(x+1,y-2));
            if(valid(x-1,y-2)&&chess[x-1][y-2]==-1)  q.push(make_pair(x-1,y-2));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX