Pagini recente » Cod sursa (job #153725) | Cod sursa (job #97881) | Cod sursa (job #3230339) | Cod sursa (job #2105209) | Cod sursa (job #819889)
Cod sursa(job #819889)
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const char InFile[]="rays.in";
const char OutFile[]="rays.out";
const int MaxN=200111;
const double PI=3.1415926535897932384626433832795;
const double RAD2DEG=180/PI;
ifstream fin(InFile);
ofstream fout(OutFile);
struct Event
{
Event(double time=0.0, int type=0):time(time),type(type){}
double time;
int type;
};
struct Event_CMP
{
inline bool operator() (const Event &A, const Event &B)
{
if(A.time==B.time)
{
return A.type>B.type;
}
return A.time<B.time;
}
};
int N,sol,done[MaxN],leftYind=-1,rightYind=-1;
double mx,my1,my2,st,dr;
Event leftY[MaxN],rightY[MaxN];
inline void Solve(Event *V,int length)
{
sort(V,V+length,Event_CMP());
int last=-1;
for(register int i=0;i<length;++i)
{
if(last==-1)
{
if(V[i].type>0)
{
++sol;
last=V[i].type;
}
}
else if(-last==V[i].type)
{
last=-1;
}
}
}
int main()
{
fin>>N;
for(register int i=1;i<=N;++i)
{
fin>>mx>>my1>>my2;
st=my1/mx;
dr=my2/mx;
if(st>dr)
{
swap(st,dr);
}
if(mx<0)
{
st=-st;
dr=-dr;
swap(st,dr);
leftY[++leftYind]=Event(st,i);
leftY[++leftYind]=Event(dr,-i);
}
else
{
rightY[++rightYind]=Event(st,i);
rightY[++rightYind]=Event(dr,-i);
}
}
fin.close();
Solve(leftY,leftYind+1);
Solve(rightY,rightYind+1);
fout<<sol;
fout.close();
return 0;
}