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

Обсуждение задачи 1003. Чётность

It's simple
Послано Cat36 24 окт 2008 21:22
//main logic

#include <stdio.h>
#include <map>
#include <iostream>
using namespace std;

map<int, bool>  exist;
map<int, bool>  odd;
map<int, int>  prev;

bool add(int a, int b,  bool c){//b>=a;
    if (!exist[b]){
      exist[b] = true;
      odd[b] = c;
      prev[b] = a;
      return true;
    };
    int  i = prev[b];
    if(i==a) return (odd[b]==c);
    if(i<a) return add(i,a-1, (c!=odd[b]));
    return add(a,i-1, (c!=odd[b]));
};
Re: It's simple
Послано Aram Shatakhtsyan (YSU) 15 фев 2009 20:37
Thank you very much, at least I solved it!
Nice problem!
Re: It's simple
Послано nguyenductam 7 апр 2010 07:29
thank you! i study very from you
Re: It's simple
Послано BaJIuK 1 ноя 2011 16:49
Thanks! nice idea ;) I've got AC thank you very much!!!)

Edited by author 01.11.2011 17:53
Re: It's simple
Послано robot1 9 дек 2011 15:56
100
5
5 6 odd
7 8 odd
1 6 even
1 4 odd
7 8 even

why result is 3 and not 4?
Re: It's simple
Послано scythe 13 дек 2011 04:10
because 1 1 = 0 but 0 0 not 1

the input format is verrrry misleading, i have lost 2 hours of my live because of it.
Re: It's simple
Послано robot1 16 дек 2011 13:00
#include <stdio.h>
#include <map>
#include <iostream>
#include <string>
using namespace std;

map<int, bool>  exist;
map<int, bool>  odd;
map<int, int>  previous;

bool add(int a, int b,  bool c){//b>=a;
    if (!exist[b]){
      exist[b] = true;
      odd[b] = c;
      previous[b] = a;
      return true;
    };
    int  i = previous[b];
    if(i==a) return (odd[b]==c);
    if(i<a) return add(i,a-1, (c!=odd[b]));
    return add(a,i-1, (c!=odd[b]));
};

int main(int argc, char * argv[]) {
    while (1) {
        exist.clear();
        odd.clear();
        previous.clear();
        int numbers = 0;
        cin >> numbers;
        if (numbers==-1) break;
        int questions = 0;
        cin >> questions;
        bool flag = false;
        for (int i = 0; i<questions; i++) {
            int a = 0;
            cin >> a;
            int b = 0;
            cin >> b;
            string tmp;
            cin >> tmp;
            bool parity = false;
            if (tmp=="even") {
                parity = true;
            }
            if ((add(a,b,parity)==false)&&(flag==false)) {
                cout << i;
                flag=true;
            }
        }
        if (flag==false) {
            cout << questions;
        }
    }
    return 0;
}

What wrong? I got wa at 1 test.
Re: It's simple
Послано vlyubin 1 мар 2012 09:45
Then run it in the debug mode and you'll figure it out.
Re: It's simple
Послано thefourtheye 21 мар 2012 22:23
change
robot1 писал(a) 16 декабря 2011 13:00
            bool parity = false;
            if (tmp=="even") {
                parity = true;
            }
to
            bool parity = true;
            if (tmp=="even") {
                parity = false;
            }
and then break after flag=true;

Edited by author 21.03.2012 22:25

Edited by author 21.03.2012 22:25
Re: It's simple
Послано khaihanhdk 2 май 2012 15:37
{
100
5
5 6 odd
7 8 odd
1 6 even
1 4 odd
7 8 even

why result is 3 and not 4?
}
I think the answer is 4, because [1,4] is odd and [5,6] is odd and [1,4],[5,6] are continuous then the answer isn't 3, but it is 4.

Edited by author 02.05.2012 15:37

Edited by author 02.05.2012 15:40

Edited by author 02.05.2012 15:40
Re: It's simple
Послано Schullz 30 окт 2012 19:12
Thanks a lot!
Re: It's simple
Послано beta 19 дек 2012 22:48
Good programing skills!! Thanks~
Re: It's simple
Послано staticor 20 июн 2013 23:08
remarkable code.
Re: It's simple
Послано Sanfeng HU 15 июл 2013 07:54
Pretty well!
Re: It's simple
Послано Duy_e 17 апр 2021 15:55
:0 this approach is out of my mind, great work!!