# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
586926 |
2022-07-01T05:19:57 Z |
반딧불(#8396) |
Mixture (BOI20_mixture) |
C++17 |
|
1 ms |
304 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Frac{
ll a, b;
Frac(){}
Frac(ll a, ll b): a(a), b(b){
ll g = __gcd(a, b);
a/=g, b/=g;
if(b<0) a=-a, b=-b;
}
Frac(ll a): a(a){
b=0;
}
Frac operator-(const Frac &r)const{
ll g = __gcd(b, r.b);
return Frac(a*(r.b/g)-r.a*(b/g), b/g*r.b);
}
Frac operator*(const Frac &r)const{
return Frac(a*r.a, b*r.b);
}
bool operator<(const Frac &r)const{
return a*r.b < b*r.a;
}
bool operator<=(const Frac &r)const{
return a*r.b < b*r.a;
}
bool operator>(const Frac &r)const{
return a*r.b > b*r.a;
}
bool operator==(const Frac &r)const{
return a*r.b == b*r.a;
}
};
struct vector2{
Frac x, y;
vector2(){}
vector2(Frac x, Frac y): x(x), y(y){}
vector2 operator-(const vector2 r)const{
return vector2(x-r.x, y-r.y);
}
bool operator<(const vector2 &r)const{
return make_pair(x, y) < make_pair(r.x, r.y);
}
bool operator==(const vector2 &r)const{
return x==r.x && y==r.y;
}
Frac cross(vector2 r)const{
return x*r.y - y*r.x;
}
};
Frac ccw(vector2 a, vector2 b){
return a.cross(b);
}
Frac ccw(vector2 a, vector2 b, vector2 c){
return (b-a).cross(c-a);
}
vector2 point;
int n;
vector2 arr[100002];
bool deleted[100002];
int arrSize;
void input(vector2 &p){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
p.x = Frac(a, a+b+c);
p.y = Frac(b, a+b+c);
}
vector<vector2> hull(vector<vector2> &vec){
vector<vector2> ret;
sort(vec.begin(), vec.end());
sort(vec.begin()+1, vec.end(), [&](vector2 A, vector2 B){
return ccw(A, vec[0], B) < 0;
});
ret.push_back(vec[0]);
for(int i=1; i<(int)vec.size(); i++){
while(ret.size()>=2 && ccw(ret[ret.size()-2], ret.back(), vec[i]) <= 0) ret.pop_back();
ret.push_back(vec[i]);
}
return ret;
}
inline int sign(Frac x){
if(x>0) return 1;
if(x<0) return -1;
return 0;
}
bool inside(vector<vector2> &vec, vector2 p){
if((int)vec.size() <= 2) return 0;
int s = sign(ccw(vec.back(), vec[0], p));
for(int i=0; i<(int)vec.size()-1; i++){
if(s != sign(ccw(vec[i], vec[i+1], p))) return false;
}
return true;
}
void calc(){
vector<vector2> vec;
for(int i=1; i<=arrSize; i++){
if(!deleted[i]){
if(arr[i] == point){
puts("1");
return;
}
vec.push_back(arr[i]);
}
}
if(vec.empty()){
puts("0");
return;
}
for(int i=0; i<(int)vec.size(); i++){
for(int j=i+1; j<(int)vec.size(); j++){
if(ccw(vec[i], vec[j], point) == 0 && (vec[i] < point) ^ (vec[j] < point)){
puts("2");
return;
}
}
}
vec = hull(vec);
if(inside(vec, point)) puts("3");
else puts("0");
}
int main(){
input(point);
scanf("%d", &n);
for(int i=1; i<=n; i++){
char c;
scanf(" %c", &c);
if(c == 'A') input(arr[++arrSize]);
else{
int x;
scanf("%d", &x);
deleted[x] = 1;
}
calc();
}
}
Compilation message
Mixture.cpp: In function 'void input(vector2&)':
Mixture.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | scanf("%d %d %d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp: In function 'int main()':
Mixture.cpp:147:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
147 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Mixture.cpp:150:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
150 | scanf(" %c", &c);
| ~~~~~^~~~~~~~~~~
Mixture.cpp:154:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
154 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Incorrect |
1 ms |
304 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |