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

Discussion of Problem 1197. Lonesome Knight

I got AC! Here is my program!
Posted by panrui 2 Jul 2004 21:23
#include<iostream.h>
int t[12][2];
int a,b;
void print()
{
    int s,x,y,i;
    s=0;
    for (i=1;i<=8;i++)
    {
    x=t[i][1];
    y=t[i][2];
    if ((b+x>=1) && (b+x<=8) && (a+y>=1) && (a+y<=8)) s++;
    }
    cout<<s<<endl;
}
void in()
{
    t[1][1]=2;t[1][2]=1;
    t[2][1]=1;t[2][2]=2;
    t[3][1]=2;t[3][2]=-1;
    t[4][1]=-1;t[4][2]=2;
    t[5][1]=-2;t[5][2]=1;
    t[6][1]=1;t[6][2]=-2;
    t[7][1]=-1;t[7][2]=-2;
    t[8][1]=-2;t[8][2]=-1;
}
void main()
{
    int n,i,j;
    char p;
    cin>>n;
    in();
    for (i=1;i<=n;i++)
    {
    cin>>p;
    a=int(p)-96;
    cin>>p;
    b=int(p)-48;
    print();
    }
}
Re: I got AC! Here is my program!
Posted by Taran_Alex 23 Sep 2007 07:09
#include <stdio.h>

int p[8][8]={2,3,4,4,4,4,3,2,
             3,4,6,6,6,6,4,3,
             4,6,8,8,8,8,6,4,
             4,6,8,8,8,8,6,4,
             4,6,8,8,8,8,6,4,
             4,6,8,8,8,8,6,4,
             3,4,6,6,6,6,4,3,
             2,3,4,4,4,4,3,2};
void main(void)
{
    int N;
    scanf("%i\n",&N);
    for(int i=0;i<N;i++)
    {
        char letter,digit;
        scanf("%c%c\n",&letter,&digit);
        int il,id;
        il=letter-'a'+1;
        id=digit-'0';
        printf("%i\n",p[il-1][id-1]);
    }
}
Re: I got AC! Here is my program!
Posted by gmsr 25 Sep 2007 18:28
#include <iostream>

using namespace std;

long mz (long xx,long yy)
{
     if ((xx<1)||(xx>8)) return (0);
     if ((yy<1)||(yy>8)) return (0);
     return (1);
}

int main ()
{
    long n;
    char str[100];
    long x,y,xx,yy;
    long i,total;
    cin>>n;
    for (i=0;i<n;i++)
        {
        cin>>str;
        total=0;
        x=(long)(str[0])-96;
        y=(long)(str[1])-48;
        xx=x+2;
        yy=y+1;
        if (mz(xx,yy)) total++;
        xx=x-2;
        yy=y+1;
        if (mz(xx,yy)) total++;
        xx=x-2;
        yy=y-1;
        if (mz(xx,yy)) total++;
        xx=x+2;
        yy=y-1;
        if (mz(xx,yy)) total++;
        xx=x+1;
        yy=y+2;
        if (mz(xx,yy)) total++;
        xx=x-1;
        yy=y+2;
        if (mz(xx,yy)) total++;
        xx=x-1;
        yy=y-2;
        if (mz(xx,yy)) total++;
        xx=x+1;
        yy=y-2;
        if (mz(xx,yy)) total++;
        cout<<total<<endl;
        }
    return (0);
}
这个比较罗嗦的
Re: I got AC! Here is my program!
Posted by Pavel Nikolov 15 Oct 2007 02:55
pls can somebody tell me why i got compilation error on this code

#include <stdio.h>
#include <stdlib.h>

inline int numberOfAttackedFields(int x, int y)
{
    int i = 0;
    if (x - 1 > 0 && y - 2 > 0)
    {
        i++;
    }

    if (x + 1 < 9 && y - 2 > 0)
    {
        i++;
    }

    if (x + 2 < 9 && y - 1 > 0)
    {
        i++;
    }

    if (x + 2 < 9 && y + 1 < 9)
    {
        i++;
    }

    if (x + 1 < 9 && y + 2 < 9)
    {
        i++;
    }

    if (x - 1 > 0 && y + 2 < 9)
    {
        i++;
    }

    if (x - 2 > 0 && y + 1 < 9)
    {
        i++;
    }

    if (x - 2 > 0 && y - 1 > 0)
    {
        i++;
    }
    return i;
}

int main(void)
{
    int x, y, n;
    char input[3];
    char firstLetter;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", input);
        input[2] = '\0';

        firstLetter = input[0];

        //lower case
        if (firstLetter - 'a' >= 0 && firstLetter - 'a' <= 8)
        {
            x = firstLetter - 'a' + 1;
        }
        //upper case
        else
        {
            x = firstLetter - 'A' + 1;
        }

        //replace the first letter with 0
        input[0] = '0';
        y = atoi(input);
        printf("x=%d y=%d\t%d\n", x, y, numberOfAttackedFields(x, y));
    }

    return 0;
}

it compiles with no problems on my MAC. I recieve compilation error on any code I submit! But no problems on my side.
Re: I got AC! Here is my program!
Posted by Nayeem Reza 23 Nov 2013 15:37
(...)
int main()
{
    int t;

    scanf("%d",&t);
    getchar();
    while(t--){
        char a[10];
        scanf("%s", a);
        int count = 0;
        if(a[0]-96-2>0 && a[1]-48-2>0) count+=2;
        else{
            if(a[0]-96-1>0 && a[1]-48-2>0) count+=1;
            if(a[0]-96-2>0 && a[1]-48-1>0) count+=1;
        }

        if(a[0]-96+2<9 && a[1]-48-2>0) count+=2;
        else{
            if(a[0]-96+1<9 && a[1]-48-2>0) count+=1;
            if(a[0]-96+2<9 && a[1]-48-1>0) count+=1;
        }

        if(a[0]-96-2>0 && a[1]-48+2<9) count+=2;
        else{
            if(a[0]-96-1>0 && a[1]-48+2<9) count+=1;
            if(a[0]-96-2>0 && a[1]-48+1<9) count+=1;
        }

        if(a[0]-96+2<9 && a[1]-48+2<9) count+=2;
        else{
            if(a[0]-96+1<9 && a[1]-48+2<9) count+=1;
            if(a[0]-96+2<9 && a[1]-48+1<9) count+=1;
        }

        cout<<count<<endl;
    }

    return 0;
}
Re: I got AC! Here is my program!
Posted by Novomir 18 Dec 2013 00:17
program Project1;
{$APPTYPE CONSOLE}
uses
  SysUtils;
var
   i,j:integer;
   kolvo, x,y,otvet: longint;
   koord:string;
   alpha:string;
begin
{$IFNDEF ONLINE_JUDGE}
   assign(input, 'input.txt');
   reset(input);
   assign(output, 'output.txt');
   rewrite(output);
{$ENDIF}

  alpha:='abcdefgh';

  readln(kolvo);
  //ff

  for i:=1 to kolvo do
        begin
         otvet:=0;
        readln(koord);
        for j:=1 to 8 do
          if koord[1]=alpha[j] then  y:=j;
          x:=strtoint(koord[2]);


        if ((x-2)>=1) and ((y-1)>=1) then otvet:=otvet+1;
        if ((x-1)>=1) and ((y-2)>=1) then otvet:=otvet+1;

        if ((x-2)>=1) and ((y+1)<=8) then otvet:=otvet+1;
        if ((x-1)>=1) and ((y+2)<=8) then otvet:=otvet+1;

        if ((x+2)<=8) and ((y-1)>=1) then otvet:=otvet+1;
        if ((x+1)<=8) and ((y-2)>=1) then otvet:=otvet+1;

        if ((x+2)<=8) and ((y+1)<=8) then otvet:=otvet+1;
        if ((x+1)<=8) and ((y+2)<=8) then otvet:=otvet+1;

        writeln(otvet);

        end;

{$IFNDEF ONLINE_JUDGE}
   close(input);
   close(output);
{$ENDIF}
end.
Re: I got AC! Here is my program!
Posted by lhyx1990 24 Jan 2014 20:05

#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

class Place {
public:
    char x;
    int y;

    bool isOnboard() {
        if (x < 'a' || x > 'h' || y < 1 || y > 8) return false;
        return true;
    }



    Place(char x, int y) {
        this->x = x;
        this->y = y;
    }

};



int main(int argc, const char * argv[])
{
    int N;
    cin >> N;


    vector<Place> places;

    for (int i = 0; i < N; i++) {
        char x;
        int y;
        cin.get(x);

        if (x == '\n') {
            i--;
            continue;
        }

        cin >> y;

        Place place (x, y);
        places.push_back(place);

    }


    for (int i = 0; i < N; i++) {
        Place place = places[i];
        int moves = 0;


        //left 2 up 1
        place.x -= 2;
        place.y -= 1;
        moves += place.isOnboard();

        //left 2 down 1
        place.y += 2;
        moves += place.isOnboard();

        //right 2 down 1
        place.x += 4;
        moves += place.isOnboard();
        //right 2 up 1
        place.y -= 2;
        moves += place.isOnboard();

        //right 1 up 2
        place.x -= 1;
        place.y -= 1;
        moves += place.isOnboard();

        //left 1 up 2
        place.x -= 2;
        moves += place.isOnboard();

        //left 1 down 2
        place.y += 4;
        moves += place.isOnboard();

        //right 1 down 2
        place.x += 2;
        moves += place.isOnboard();

        cout << moves << endl;

    }



}

Edited by author 24.01.2014 20:05
Re: I got AC! Here is my program!
Posted by Alexander Parunov 27 Jan 2015 03:32
This is simply a bruteforce solution, but it is pretty clear though. ;)

#include <iostream>
using namespace std;
int check(int r,int c)
{
    int counter=0;
    if((r-1)>=0&&(c-2)>=0) counter++;
    if((r-1)>=0&&(c+2)<=7) counter++;
    if((r+1)<=7&&(c-2)>=0) counter++;
    if((r+1)<=7&&(c+2)<=7) counter++;
    if((c-1)>=0&&(r+2)<=7) counter++;
    if((c-1)>=0&&(r-2)>=0) counter++;
    if((c+1)<=7&&(r-2)>=0) counter++;
    if((c+1)<=7&&(r+2)<=7) counter++;
    return counter;
}
int main()
{
   char v;
   int h,i,vint,n;
   cin >> n;
   for(i=0;i<n;i++)
   {
   cin >> v>>h;
   h--;
   vint=int(v)-97;
   cout<<check(h,vint)<<endl;
   }
}