#include <stdio.h>
#include <limits.h>
typedef long long llong;
int sign(llong x) { return (x < 0) ? -1 : (x > 0) ? 1 : 0; }
struct mixture {
llong a, b, c;
llong s;
mixture() {}
mixture(llong a, llong b, llong c) : a(a), b(b), c(c), s(a+b+c) {}
} mixtures[100005];
bool mixtureValid[100005];
int line_side(const mixture& a, const mixture& b, const mixture& x) {
return sign(
(a.b*b.s - a.s*b.b) * (a.a*x.s - a.s*x.a) -
(a.a*b.s - a.s*b.a) * (a.b*x.s - a.s*x.b)
);
}
bool can_combine(const mixture& a, const mixture& x) {
return
a.a*x.s == a.s*x.a &&
a.b*x.s == a.s*x.b &&
a.c*x.s == a.s*x.c
;
}
bool can_combine(const mixture& a, const mixture& b, const mixture& x) {
return line_side(a, b, x) == 0;
}
bool can_combine(const mixture& a, const mixture& b, const mixture& c, const mixture& x) {
return
line_side(a, b, x) == line_side(a, b, c) &&
line_side(a, c, x) == line_side(a, c, b) &&
line_side(b, c, x) == line_side(b, c, a)
;
}
int main() {
int xA, xB, xC;
scanf("%d %d %d", &xA, &xB, &xC);
mixture x(xA, xB, xC);
int N;
scanf("%d", &N);
for(int i = 0; i < N; i++) {
char chr;
for(chr = getchar(); chr != 'A' && chr != 'R'; chr = getchar());
if(chr == 'A') {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
mixtures[i] = mixture(a, b, c);
mixtureValid[i] = true;
} else {
int r;
scanf("%d", &r);
mixtureValid[r-1] = false;
}
int best = INT_MAX;
for(int a = 0; a <= i; a++) {
if(!mixtureValid[a]) continue;
if(best > 1 && can_combine(mixtures[a], x)) best = 1;
for(int b = a+1; b <= i; b++) {
if(!mixtureValid[b]) continue;
if(best > 2 && can_combine(mixtures[a], mixtures[b], x)) best = 2;
for(int c = b+1; c <= i; c++) {
if(!mixtureValid[c]) continue;
if(best > 3 && can_combine(mixtures[a], mixtures[b], mixtures[c], x)) best = 3;
}
}
}
if(best == INT_MAX) best = 0;
printf("%d\n", best);
}
return 0;
}
Compilation message
Mixture.cpp: In function 'int main()':
Mixture.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d %d %d", &xA, &xB, &xC);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
Mixture.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:62:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | scanf("%d", &r);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |