Cod sursa(job #2541498)

Utilizator Iulia25Hosu Iulia Iulia25 Data 8 februarie 2020 14:54:02
Problema Rays Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

ifstream fin ("rays.in");
ofstream fout ("rays.out");

int n, _x, _y1, _y2, ans;
double unghi1, unghi2;

vector <pair <double, double> > v1, v2;

void solve(vector <pair <double, double> > v)	 {
	sort (v.begin(), v.end());
	double x = -2e9;
  for (auto it : v)	 {
    if (it.first > x)	 {
			++ans;
			x = it.second;
    }
    else x = min(x, it.second);
  }
}

int main()	{
	fin >> n;
	for (int i = 1; i <= n; ++i)	{
		fin >> _x >> _y1 >> _y2;
		unghi1 = atan2(_y1, _x);
		unghi2 = atan2(_y2, _x);
		if (unghi2 < unghi1)
			swap(unghi2, unghi1);
		if (_x > 0)	 {
			v1.push_back({unghi1, unghi2});
		} else
			v2.push_back({unghi1, unghi2});
	}
	solve(v1);
	solve(v2);
	fout << ans;
	return 0;
}