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 1184. Cable Master

Why I have ACCESS_VIOLATION (C++) ?
Posted by sikee8 10 Apr 2002 21:22
#include <iostream.h>

int n,k;
long m [10000],how [10000];

long GetNewLength ()
{
    long NewLength = 0;
    for (int i=1; i<=n; i++)
        if (m[i]/(how[i]+1) > NewLength) NewLength = m[i]/(how
[i]+1);
    return NewLength;
}

int main ()
{
    long nowLength = 2147483648, nowN = 0;
    double length;
    cin >> n >> k;
    for (int i=1; i<=n; i++)
    {
        cin >> length;
        m [i] = int (length * 100);
        if (m[i] < nowLength) nowLength = m [i];
    }
    while (nowN<k && nowLength != 0)
    {
        nowLength = GetNewLength ();
        if (!nowLength) continue;
        nowN = 0;
        for (i=1; i<=n; i++)
        {
            how [i] = m [i] / nowLength;
            nowN = nowN + how [i];
        }
    }
    cout << nowLength/100 << ".";
    int tens = nowLength%100;
    if (tens < 10) cout << "0" << tens;
        else cout << tens;
    return 0;
}