ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1197. Один в поле воин

WA#2. What's wrong? Please help!
Послано prime 5 авг 2016 17:46
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
int n, m, i;
char l, dt;
cin>>n;
for(i=0;i<n;i++){

    cin>>l>>dt;
        if(l=='a' && dt=='1' ||l=='a' && dt=='8' ||l=='h' && dt=='1' ||l=='h' && dt=='8')
        {
            m=2;
            cout<<m<<endl;
        }
        if(l=='a' && dt=='2' ||l=='a' && dt=='7' ||l=='b' && dt=='1' ||l=='b' && dt=='8' ||l=='g' && dt=='1'||l=='g' && dt=='8'||l=='h' && dt=='2'||l=='h' && dt=='7')
        {
            m=3;
            cout<<m<<endl;
        }
        if(l=='a' && dt=='3' ||l=='a' && dt=='4' ||l=='a' && dt=='5' ||l=='a' && dt=='6' ||l=='b' && dt=='2'||l=='b' && dt=='7'||l=='c' && dt=='1'||l=='d' && dt=='1'||l=='e' && dt=='1'||l=='f' && dt=='1'||l=='c' && dt=='8'||l=='d' && dt=='8'||l=='e' && dt==8||l=='f' && dt=='8'||l=='g' && dt=='7'||l=='g' && dt=='2'||l=='h' && dt=='3'||l=='h' && dt=='4'||l=='h' && dt=='5'||l=='h' && dt=='6')
        {
            m=4;
            cout<<m<<endl;
        }
        if(l=='b' && dt=='3' ||l=='b' && dt=='4' ||l=='b' && dt=='5' ||l=='b' && dt=='6' ||l=='c' && dt=='2' ||l=='d' && dt=='2' ||l=='e' && dt=='2' ||l=='f' && dt=='2' ||l=='c' && dt=='7' ||l=='d' && dt=='7'||l=='e' && dt=='7'||l=='f' && dt=='7'||l=='g' && dt=='3'||l=='g' && dt=='4'||l=='g' && dt=='5'||l=='g' && dt=='6')
        {
            m=6;
            cout<<m<<endl;
        }
        if(l=='c' && dt=='3' ||l=='c' && dt=='4' ||l=='c'&& dt=='5' ||l=='c' && dt=='6' ||l=='d' && dt=='3' ||l=='d' && dt=='4' ||l=='d' && dt=='5' ||l=='d' && dt=='6' ||l=='e' && dt=='3' ||l=='e' && dt=='4' ||l=='e' && dt=='5' ||l=='e' && dt=='6' ||l=='f' && dt=='3' ||l=='f' && dt=='4' ||l=='f' && dt=='5' ||l=='f' && dt=='6')
        {
            m=8;
            cout<<m<<endl;
        }
}
    return 0;
}

I checked all values but something is wrong... That works on my IDE...
Sorry, i am noob but this solution must work fine!
Re: WA#2. What's wrong? Please help!
Послано Oleg Baskakov 5 авг 2016 22:47
This is bad, you shouldn't code this way. What if chessboard was 1000x1000 instead of 8x8? Check out this link http://acm.timus.ru/forum/thread.aspx?id=32538&upd=635922147004042008
A test_horse function from there is more universal and it can check the amount of moves from any given x and y. You should use something like that instead. Otherwise it's very hard to tell where the error is.
Re: WA#2. What's wrong? Please help!
Послано falicos 5 авг 2016 23:07
this cod is very hard to check. I make the folowing program
for(l='a'; l<='h';l++){
    for(dt='1';dt<='8';dt++){
     ____________________________
     this is your cod
     only replace
     cout<<m<<endl;
     with this one
     cout<<m<<' ';
     _____________________________
     }
     cout<<endl;
}
and compare your answer
             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,6,8,8,8,8,6,4
             3,4,6,6,6,6,4,3,
             2,3,4,4,4,4,3,2
 with the write answer
             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
It is evident that you miss one case e8. I add this case in the branch where m=4,and AC. And even if chessboard was 1000x1000 the best solution is precalc. Good luck.


Edited by author 05.08.2016 23:08

Edited by author 05.08.2016 23:11

Edited by author 05.08.2016 23:14

Edited by author 05.08.2016 23:19