Pagini recente » Cod sursa (job #1501816) | Cod sursa (job #3132852) | Cod sursa (job #2731421) | Cod sursa (job #2406750) | Cod sursa (job #1520325)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("rays.in");
ofstream out("rays.out");
struct segm{
long long x, y1, y2;
};
int n, rasp;
vector <segm> vp, vn;
segm aux;
bool cmp(segm a, segm b)
{
return (a.y2 * b.x < a.x * b.y2);
}
void rezolva(vector <segm> &v)
{
sort (v.begin(), v.end(), cmp);
if (!v.empty())
{
int x = v[0].x;
int y = v[0].y2;
rasp++;
for(int i = 1; i<v.size(); i++)
{
if(y * v[i].x<x * v[i].y1)
{
rasp++;
x = v[i].x;
y = v[i].y2;
}
}
}
}
int main()
{
int player_unu=0;
in>>n;
for (int i = 1; i<=n; i++)
{
in>>aux.x>>aux.y1>>aux.y2;
if (aux.y1>aux.y2)
swap(aux.y1, aux.y2);
if (aux.x>0)
{
vp.push_back(aux);
}
else
{
aux.x *= -1;
vn.push_back(aux);
}
}
rezolva(vp);
rezolva(vn);
out<<rasp<<'\n';
return 0;
}