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

Common Board

1772: Лыжни для роботов
Posted by vigosslive 3 Jan 2012 01:11
why my solution does not work. If I understand correctly that the fallen robots leave only one open ski runs and it turns out that only the extreme can be free. If anyone can help please contact us by e-mail: programmer_box@rambler.ru

here is the source of my decisions:


#include <iostream>
using namespace std;
int main()
{
    register int i;
    int time = 0;  // количество секунд
    int free_road = 0; // номер свободной дорожки
    int n, s, k;
    cin >> n >> s >> k;
    int *arr;
    arr = new int[k*2]; // массив содержащий координаты упавших роботов
    for(int j=0; j!=(k*2); j++)
    {
        cin >> arr[j] >> arr[++j]; // здесь инициализируем массив
    }

if(k != 0) {
    for(i=0; i!=(k*2); i++)
    {
        if(arr[i]<s && arr[i+1]<s)
        {
            i++;
            continue;
        }
        else
        {
            if(arr[i+1] == n)
            {
                free_road = arr[i] - 1;

                time += (s - free_road);
                s = free_road;
                i++;


            } else
            {
                free_road = arr[i+1] + 1;
                time += (free_road - s);
                s = free_road;
                i++;

            }

        }
    }
}
    cout << time << endl;

    return 0;
}