Rezultati

Up. imeNalogaJezikRezultatČas oddaje
lml-2018 Fruit Ninja C++ Se ne prevede 13. okt '18 @ 12:21

Izpis prevajalnika:
source.c++: In function ‘int main()’:
source.c++:30:76: error: call of overloaded ‘abs(double)’ is ambiguous
                 if(abs((sy * x2 + sx * y1 - sy * x1 - sx * y2)/(2 * length)) <= r)
                                                                            ^
In file included from /usr/include/c++/5/cstdlib:72:0,
                 from /usr/include/c++/5/bits/stl_algo.h:59,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
source.c++:7:8: note: candidate: double abs(double)
 double abs(double x)
        ^
In file included from /usr/include/c++/5/random:38:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/c++/5/cmath:91:3: note: candidate: constexpr long double std::abs(long double)
   abs(long double __x)
   ^
/usr/include/c++/5/cmath:87:3: note: candidate: constexpr float std::abs(float)
   abs(float __x)
   ^
/usr/include/c++/5/cmath:81:3: note: candidate: constexpr double std::abs(double)
   abs(double __x)
   ^
In file included from /usr/include/c++/5/bits/stl_algo.h:59:0,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/c++/5/cstdlib:174:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
/usr/include/c++/5/cstdlib:166:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
source.c++:47:76: error: call of overloaded ‘abs(double)’ is ambiguous
                 if(abs((sy * x2 + sx * y1 - sy * x1 - sx * y2)/(2 * length)) <= r)
                                                                            ^
In file included from /usr/include/c++/5/cstdlib:72:0,
                 from /usr/include/c++/5/bits/stl_algo.h:59,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
source.c++:7:8: note: candidate: double abs(double)
 double abs(double x)
        ^
In file included from /usr/include/c++/5/random:38:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/c++/5/cmath:91:3: note: candidate: constexpr long double std::abs(long double)
   abs(long double __x)
   ^
/usr/include/c++/5/cmath:87:3: note: candidate: constexpr float std::abs(float)
   abs(float __x)
   ^
/usr/include/c++/5/cmath:81:3: note: candidate: constexpr double std::abs(double)
   abs(double __x)
   ^
In file included from /usr/include/c++/5/bits/stl_algo.h:59:0,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/c++/5/cstdlib:174:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
/usr/include/c++/5/cstdlib:166:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
source.c++:70:76: error: call of overloaded ‘abs(double)’ is ambiguous
                 if(abs((sy * x2 + sx * y1 - sy * x1 - sx * y2)/(2 * length)) <= r)
                                                                            ^
In file included from /usr/include/c++/5/cstdlib:72:0,
                 from /usr/include/c++/5/bits/stl_algo.h:59,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
source.c++:7:8: note: candidate: double abs(double)
 double abs(double x)
        ^
In file included from /usr/include/c++/5/random:38:0,
                 from /usr/include/c++/5/bits/stl_algo.h:66,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/c++/5/cmath:91:3: note: candidate: constexpr long double std::abs(long double)
   abs(long double __x)
   ^
/usr/include/c++/5/cmath:87:3: note: candidate: constexpr float std::abs(float)
   abs(float __x)
   ^
/usr/include/c++/5/cmath:81:3: note: candidate: constexpr double std::abs(double)
   abs(double __x)
   ^
In file included from /usr/include/c++/5/bits/stl_algo.h:59:0,
                 from /usr/include/c++/5/algorithm:62,
                 from source.c++:3:
/usr/include/c++/5/cstdlib:174:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
/usr/include/c++/5/cstdlib:166:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
source.c++:18:52: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&n);
                                                    ^
source.c++:24:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lf %lf %lf",&sx,&sy,&r);
                                        ^

Ocenjevani program (Ninja.cpp):
#include <stdio.h>
#include <math.h>
#include <algorithm>

using namespace std;

double abs(double x)
{
    if(x < 0)
        return 0-x;
    
    return x;
}

int main()
{
    double x1, y1, x2, y2, n, sx, sy, r;
    scanf("%lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&n);
    double length = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    int res = 0;

    for(int i = 0; i < n; i++)
    {
        scanf("%lf %lf %lf",&sx,&sy,&r);

        if(y1 == y2)
        {
            if((x1 - sx) * (x2 - sx) < 0)
            {
                if(abs((sy * x2 + sx * y1 - sy * x1 - sx * y2)/(2 * length)) <= r)
                {
                    res++;
                }
            }
            else
            {
                if(min((x1 - sx) * (x1 - sx) + (y1 - sy) * (y1 - sy),(x2 - sx) * (x2 - sx) + (y2 - sy) * (y2 - sy)) <= r * r)
                {
                    res++;
                }
            }
        }
        else if(x1 == x2)
        {
            if((y1 - sy) * (y2 - sy) < 0)
            {
                if(abs((sy * x2 + sx * y1 - sy * x1 - sx * y2)/(2 * length)) <= r)
                {
                    res++;
                }
            }
            else
            {
                if(min((x1 - sx) * (x1 - sx) + (y1 - sy) * (y1 - sy),(x2 - sx) * (x2 - sx) + (y2 - sy) * (y2 - sy)) <= r * r)
                {
                    res++;
                }
            }
        }
        else
        {
            double k = (y2 - y1)/(x2 - x1);
            double i = 1/k;
            double n = 0 - k * x1 + y1;
            int c = (k - i) * x1 + n;
            int d = (k - i) * x2 + n;

            if((i * sx + c - sy) * (i * sx + d - sy) < 0)
            {
                if(abs((sy * x2 + sx * y1 - sy * x1 - sx * y2)/(2 * length)) <= r)
                {
                    res++;
                }
            }
            else
            {
                if(min((x1 - sx) * (x1 - sx) + (y1 - sy) * (y1 - sy),(x2 - sx) * (x2 - sx) + (y2 - sy) * (y2 - sy)) <= r * r)
                {
                    res++;
                }
            }
        }
    }

    printf("%d\n",res);
}