Rezultati

Up. imeNalogaJezikRezultatČas oddaje
ASMx64-2018 Fruit Ninja C++ 100/100OK 13. okt '18 @ 13:07

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 3,125 MiB 0,004 s OK
#2 11/11 3,125 MiB 0,010 s OK
#3 11/11 3,207 MiB 0,000 s OK
#4 11/11 3,145 MiB 0,010 s OK
#5 11/11 3,176 MiB 0,000 s OK
#6 11/11 3,145 MiB 0,004 s OK
#7 11/11 3,238 MiB 0,004 s OK
#8 11/11 3,238 MiB 0,000 s OK
#9 12/12 3,145 MiB 0,010 s OK

Ocenjevani program (fruitPanther.cpp):
#include <iostream>
//#include <fstream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;


struct Tocka {
    double x, y;
};

struct Krog {
    double p, q, r;
};

vector<double> solve(Krog krog, double k, double n){
    vector<double> solutions;
    double a = k*k+1;
    double b = 2*k*n - 2*k*krog.q - 2*krog.p;
    double c = krog.p*krog.p + n*n - 2*krog.q*n + krog.q*krog.q - krog.r*krog.r;
    double D = b*b-4*a*c;
   // cout <<" D = " << D << " " << ((-b+sqrt(D))/2/a)  << " " << ((-b-sqrt(D))/2/a) << endl;
    if (D<0) return solutions;
    solutions.push_back((-b+sqrt(D))/2/a);
    solutions.push_back((-b-sqrt(D))/2/a);
    return solutions;
}

double razd(double p, double q, Tocka t){
    return sqrt((p-t.x)*(p-t.x) + (q-t.y)*(q-t.y));
}

int main()
{
    Tocka A, B;
    cin >> A.x >> A.y >> B.x >> B.y;
    int N;
    cin >> N;
    Krog krogi[N];
    for (int i=0; i<N; i++) {
        cin >> krogi[i].p >> krogi[i].q >> krogi[i].r;
    }
    int zadetki=0;
    double k, n;
    if (A.x==B.x) {
        for(int i =0; i<N; i++){
            if ((krogi[i].p-krogi[i].r)>A.x || (krogi[i].p+krogi[i].r)<A.x) {
                continue;
            }
            double d1 = razd(krogi[i].p, krogi[i].q, A); double d2 = razd(krogi[i].p, krogi[i].q, B);
            if(d1 == krogi[i].r || d2 == krogi[i].r){
                zadetki++;
               // cout << i << " tocno na kroznici\n";
                continue;
            }
            if (max(d1, d2)>=krogi[i].r && min(d1, d2)<=krogi[i].r){
              //  cout << i << "ena ven, druga not\n";
                zadetki++; continue;
            }
            if (d1>krogi[i].r && d2>krogi[i].r){
                if (max(A.y, B.y)>krogi[i].q && min(A.y, B.y)<krogi[i].q) {
                 //   cout << i << "obe ven, druga not\n";
                    zadetki++;
                }
            }
            if(d1 <= krogi[i].r && d2 <= krogi[i].r){
                zadetki++;
            }
        }
        cout << zadetki << endl;
        return 0;
    }
    else {
        if (A.x>B.x){ //menjaj tocki ce sta zamenjani
            Tocka temp;
            temp.x = A.x; temp.y = A.y;
            A.x=B.x; A.y=B.y;
            B.x=temp.x; B.y=temp.y;
        }
        k=(A.y-B.y)/(A.x-B.x);
        n=A.y-k*A.x;
    }

    for(int i=0; i<N; i++){
        if(razd(krogi[i].p, krogi[i].q, A) <= krogi[i].r && razd(krogi[i].p, krogi[i].q, B) <= krogi[i].r){
            zadetki++;
            continue;
        }
        vector<double> resitve = solve(krogi[i], k, n);
        for(int j=0; j<(int)resitve.size(); j++){
            //cout << i << ": " << krogi[i].p << " " << krogi[i].q << "\t" << resitve[j] << endl;
            if (resitve[j]>=A.x && resitve[j]<=B.x) { zadetki++; break;}
        }
    }
    cout << zadetki << endl;
    return 0;
}