Pagini recente » Cod sursa (job #173259) | Cod sursa (job #1307835) | Cod sursa (job #930949) | Cod sursa (job #2040574) | Cod sursa (job #1980040)
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
using namespace std;
const int MAX_N = 2.e5;
const int BUF_SIZE = 4096;
char buf[BUF_SIZE + 5];
int poz = BUF_SIZE;
char nextChar() {
if (poz == BUF_SIZE) {
fread(buf, 1, BUF_SIZE, stdin);
poz = 0;
}
return buf[poz++];
}
int read() {
char c;
do {
c = nextChar();
} while (!isdigit(c) && c != '-');
int sgn = 1;
if (c == '-') {
sgn = -1;
c = nextChar();
}
int nr = 0;
do {
nr = nr * 10 + c - '0';
c = nextChar();
} while (isdigit(c));
return sgn * nr;
}
struct Punct {
int x;
int y;
};
struct Baleiere {
Punct P;
int index;
bool tip;
bool operator < (const Baleiere& other) const {
if ((long long)P.y * other.P.x == (long long)other.P.y * P.x)
return tip > other.tip;
return (long long)P.y * other.P.x > (long long)other.P.y * P.x;
}
};
int N;
int kPozitiv, kNegativ;
int raze;
int viz[MAX_N + 5];
Baleiere rezolvaPozitiv[2 * MAX_N + 5];
Baleiere rezolvaNegativ[2 * MAX_N + 5];
inline int rezolva(Baleiere rez[], int K) {
sort(rez + 1, rez + K + 1);
int ans = 0;
for (int i = 1; i <= K; ++i) {
if (rez[i].tip == 1)
viz[rez[i].index] = ans + 1;
else if (viz[rez[i].index] == ans + 1)
ans++;
}
return ans;
}
int main() {
freopen("rays.in", "r", stdin);
freopen("rays.out", "w", stdout);
N = read();
for (int i = 1; i <= N; ++i) {
int x = read();
int y1 = read();
int y2 = read();
if (y1 < y2)
swap(y1, y2);
if (x > 0) {
rezolvaPozitiv[++kPozitiv] = {{x, y1}, i, 1};
rezolvaPozitiv[++kPozitiv] = {{x, y2}, i, 0};
} else { /// x < 0
rezolvaNegativ[++kNegativ] = {{x, y1}, i, 0};
rezolvaNegativ[++kNegativ] = {{x, y2}, i, 1};
}
}
raze += rezolva(rezolvaPozitiv, kPozitiv);
raze += rezolva(rezolvaNegativ, kNegativ);
printf("%d\n", raze);
return 0;
}