Cod sursa(job #1500849)

Utilizator ArkinyStoica Alex Arkiny Data 12 octombrie 2015 19:10:11
Problema Rays Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#include<fstream>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;

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

#define MAX 200001

#define swap(t,a,b)(t=a,a=b,b=t)

struct LINE
{
	int x;
	double a_y1,a_y2;
};

LINE v1[MAX],v2[MAX];
int N, v1_l=0, v2_l=0;

bool sort_f_1(LINE e1, LINE e2)
{
	return e1.a_y2 < e2.a_y2;
}
bool sort_f_2(LINE e1, LINE e2)
{
	return e1.a_y1 < e2.a_y1;
}

int main()
{
	in >> N;
	int x, y1, y2,t;
	while (in >> x >> y1 >> y2)
	{
		if (x > 0)
		{
			v1[++v1_l].x = x;
			if (y1 > y2)
				swap(t, y1, y2);
			v1[v1_l].a_y1 = (double)y1 / x;
			v1[v1_l].a_y2 = (double)y2 / x;
		}
		else
		{
			v2[++v2_l].x = x;
			if (y1 > y2)
				swap(t, y1, y2);
			v2[v2_l].a_y1 = (double)y1 / x;
			v2[v2_l].a_y2 = (double)y2 / x;
		}
		
	}
	int sol = 1;
	sort(v1 + 1, v1 + v1_l + 1, sort_f_1);
	int j = 1;
	for (int i = 2;i <= v1_l;++i)
	{
		if (v1[i].a_y1 > v1[j].a_y2)
		{
			++sol;
			j = i;
		}
	}
	sort(v2 + 1, v2 + v2_l + 1, sort_f_2);

	j = 1;
	++sol;
	for (int i = 2;i <= v2_l;++i)
	{
		if (v2[i].a_y2 > v2[j].a_y1)
		{
			++sol;
			j = i;
		}
	}
	out << sol;
	return 0;
}