Pagini recente » Cod sursa (job #3181148) | Cod sursa (job #501703) | Cod sursa (job #2356678) | Cod sursa (job #2358807) | Cod sursa (job #3187969)
#include <bits/stdc++.h>
using namespace std;
vector<pair<double,double>>poz,neg;
bool cmp(pair<double,double> a,pair<double,double> b){
return a.first < b.first;
}
ifstream fin("rays.in");
ofstream fout("rays.out");
int n;
int main(){
fin>>n;
for(int i=1;i<=n;i++){
int x,y,y2; fin>>x>>y>>y2;
if(y2<y)
swap(y2,y);
double u1 = atan2(y,abs(x));
double u2 = atan2(y2,abs(x));
if(x>=0)
poz.push_back({u1,u2});
else
neg.push_back({u1,u2});
}
int rez = 0;
sort(poz.begin(),poz.end(),cmp);
sort(neg.begin(),neg.end(),cmp);
rez+=2;
double aux = poz[0].second;
for(int i=1;i<poz.size();i++){
double jos = poz[i].first;
double sus = poz[i].second;
if(jos < aux)
aux = min(aux,sus);
else
rez++,aux = sus;
}
aux = neg[0].second;
for(int i=1;i<neg.size();i++){
double jos = neg[i].first;
double sus = neg[i].second;
if(jos < aux)
aux = min(aux,sus);
else
rez++,aux = sus;
}
fout<<rez;
return 0;
}