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 1777. Anindilyakwa

WA#17
Posted by RocBoy-D 7 Aug 2012 19:15
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b)
{
    unsigned long long *pa = (unsigned long long *)a,
    *pb = (unsigned long long *)b;
    return *(unsigned long long *)pa - *(unsigned long long *)pb;
}


int main()
{
    unsigned long long arr[15000], min=1000000000000000000;
    int N=3, count=0, i;

    for(i = 0; i<N; i++)
        scanf("%llu", &arr[i]);
    while(min)
    {
        qsort (arr, N, sizeof(unsigned long long), cmp);
        for (i = 0; i<N-1; i++)
            if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i];
        arr[N++] = min;
        count++;
    }
    printf("%d", count);

    return 0;
}
Can anybody help me?
Re: WA#17
Posted by Andrew Sboev [USU] 7 Aug 2012 21:07
Use __int64 instead of unsigned long long
Re: WA#17
Posted by RocBoy-D 7 Aug 2012 21:41
I changed. But I stil have WA#17 and time limit exceed.
Re: WA#17
Posted by RocBoy-D 7 Aug 2012 21:52
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b)
{
    __int64 *pa = (__int64 *)a,
    *pb = (__int64 *)b;
    return *(__int64 *)pa - *(__int64 *)pb;
}


int main()
{
    __int64 arr[100], min=1000000000000000000;
    int N=3, count=0, i;

    for(i = 0; i<N; i++)
    scanf("%I64d", &arr[i]);
    while(min)
    {
        qsort (arr, N, sizeof(__int64), cmp);
        for (i = 0; i<N-1; i++)
            if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i];
        arr[N++] = min;
        count++;
    }
    printf("%d", count);

    return 0;
}
Now I have WA#17 and crash(acces violation).
Re: WA#17
Posted by Andrew Sboev [USU] 7 Aug 2012 22:29
Of course, you have crash :D Replace all number types to __int64, uncluding int.
Re: WA#17
Posted by RocBoy-D 7 Aug 2012 22:59
I changed:
#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b)
{
    __int64 *pa = (__int64 *)a,
    *pb = (__int64 *)b;
    return *(__int64 *)pa - *(__int64 *)pb;
}


int main()
{
    __int64 arr[100], min=1000000000000000000, N=3, count=0, i;

    for(i = 0; i<N; i++)
        scanf("%I64d", &arr[i]);
    while(min)
    {
        qsort (arr, N, sizeof(__int64), cmp);
        for (i = 0; i<N-1; i++)
            if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i];
        arr[N++] = min;
        count++;
    }
    printf("%I64d", count);

    return 0;
}
But the same problem remain: WA#17 crasn(access violation)
Re: WA#17
Posted by Andrew Sboev [USU] 8 Aug 2012 11:02
You didn't changed
int cmp(const void *a, const void *b)
{
    __int64 *pa = (__int64 *)a,
    *pb = (__int64 *)b;
    return *(__int64 *)pa - *(__int64 *)pb;
}

change to

__int64 cmp(const void *a, const void *b)
{
    __int64 *pa = (__int64 *)a,
    *pb = (__int64 *)b;
    return *(__int64 *)pa - *(__int64 *)pb;
}
Re: WA#17
Posted by RocBoy-D 8 Aug 2012 16:09
#include <stdio.h>
#include <stdlib.h>

__int64 cmp(const void *a, const void *b)
{
    __int64 *pa = (__int64 *)a,
    *pb = (__int64 *)b;
    return *(__int64 *)pa - *(__int64 *)pb;
}

int main()
{
    __int64 arr[100], min=1000000000000000000, N=3, count=0, i;

    for(i = 0; i<N; i++)
        scanf("%I64d", &arr[i]);
    while(min)
    {
        qsort (arr, N, sizeof(__int64), cmp);
        for (i = 0; i<N-1; i++)
            if(arr[i+1] - arr[i]<min) min=arr[i+1] - arr[i];
        arr[N++] = min;
        count++;
    }
    printf("%I64d", count);

    return 0;
}
No, it doesn't help.
Re: WA#17
Posted by Andrew Sboev [USU] 8 Aug 2012 17:27
Oh,you have too small array size. Use STL vector do it greater.
Re: WA#17
Posted by RocBoy-D 8 Aug 2012 18:31
I don't know C++. I tried to change size of array, but I have time limit exceed.

Edited by author 08.08.2012 18:32
Re: WA#17
Posted by bekmyrat 6 Mar 2013 23:21
# include <iostream>
# include <vector>
# include <algorithm>
using namespace std;
long long q;
int main()
{
    vector <long long> v(3),v1;

    for(int i=0; i<3; i++)
    cin>>v[i];

    while(1)
    {
        v1.clear();

        q++;

        for(int i=0; i<(int)v.size(); i++)
        {
            for(int h=0; h<(int)v.size(); h++)
            {
                if(i!=h)
                {
                    int a=v[i]-v[h];

                    if(a>=0)
                    v1.push_back(a);
                }
            }
        }

        sort(v1.begin(),v1.end());

        if(v1[0]==0)
        {break;}

        v.push_back(v1[0]);
    }
    cout<<q;
}