# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
380912 |
2021-03-23T14:36:06 Z |
fl0rian |
Tri (CEOI09_tri) |
C++14 |
|
263 ms |
3052 KB |
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000+10
#define rep(i,N) for(int i=0;i<N;i++)
int N,K;
typedef struct point{
int x;
int y;
point(int x1,int y1){
x=x1;
y=y1;
}
point(){
}
//pre : no points exactly on the line
bool isover(point * b,point * a){
//cout << "da ("<<a->x<<","<<a->y<<") " << "a ("<<b->x<<","<<b->y<<") \n";
int v1[2] = {b->x - a->x, b->y - a->y};
int v2[2] = {b->x - x, b->y - y};
int xp = v1[0]*v2[1] - v1[1]*v2[0];
return xp>0;
}
bool isunder(point * a,point * b){
return !isover(a,b);
}
} * P;
point origin(0,0);
typedef struct triangle{
point a;
point b;
bool isInside(point x){
return x.isover(&origin,&b) && x.isunder(&origin,&a) && x.isunder(&a,&b);
}
bool insideTrigon(point s){
int as_x = s.x-a.x;
int as_y = s.y-a.y;
bool s_ab = (b.x-a.x)*as_y-(b.y-a.y)*as_x > 0;
if((origin.x-a.x)*as_y-(origin.y-a.y)*as_x > 0 == s_ab) return false;
if((origin.x-b.x)*(s.y-b.y)-(origin.y-b.y)*(s.x-b.x) > 0 != s_ab) return false;
return true;
}
triangle(){
}
} * T;
vector<point> points(MAXN);
vector<triangle> triangles(MAXN);
bool solve(int t){
rep(i,N)
if(triangles[t].insideTrigon(points[i]))
return true;
return false;
}
int mi22n(){
point a(4,4);
point b(6,3);
cout << "da ("<<a.x<<","<<a.y<<") " << "a ("<<b.x<<","<<b.y<<") \n";
point a3(8,3);
if(a3.isover(&a,&b))
cout<<"sopra";
else
cout<<"sotto";
}
int main(){
//freopen("int.txt","r",stdin);
cin>>N>>K;
rep(i,N){
cin >> points[i].x>> points[i].y;
//cout << "("<<points[i].x<<","<<points[i].y<<") = " <<atan2(points[i].x,-points[i].y) << "\n";
}
rep(i,K){
int q,w,e,r;
cin>>q>>w>>e>>r;
if(q<e){
triangles[i].a.x=q;
triangles[i].a.y=w;
triangles[i].b.x=e;
triangles[i].b.y=r;
}else{
triangles[i].b.x=q;
triangles[i].b.y=w;
triangles[i].a.x=e;
triangles[i].a.y=r;
}
}
rep(i,K)
cout<<(solve(i)?"Y":"N")<<"\n";
return 0;
}
Compilation message
tri.cpp: In member function 'bool triangle::insideTrigon(point)':
tri.cpp:51:52: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
51 | if((origin.x-a.x)*as_y-(origin.y-a.y)*as_x > 0 == s_ab) return false;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
tri.cpp:53:62: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
53 | if((origin.x-b.x)*(s.y-b.y)-(origin.y-b.y)*(s.x-b.x) > 0 != s_ab) return false;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
tri.cpp: In function 'int mi22n()':
tri.cpp:86:1: warning: no return statement in function returning non-void [-Wreturn-type]
86 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
364 KB |
Output is correct |
2 |
Incorrect |
2 ms |
364 KB |
Output isn't correct |
3 |
Incorrect |
57 ms |
1132 KB |
Output isn't correct |
4 |
Incorrect |
107 ms |
1644 KB |
Output isn't correct |
5 |
Incorrect |
219 ms |
3052 KB |
Output isn't correct |
6 |
Incorrect |
196 ms |
2412 KB |
Output isn't correct |
7 |
Incorrect |
254 ms |
2796 KB |
Output isn't correct |
8 |
Incorrect |
205 ms |
2356 KB |
Output isn't correct |
9 |
Incorrect |
239 ms |
2660 KB |
Output isn't correct |
10 |
Incorrect |
263 ms |
2796 KB |
Output isn't correct |