QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217626 | #5106. Islands from the Sky | mateoforerof | WA | 1ms | 4208kb | C++20 | 3.2kb | 2023-10-17 04:31:00 | 2023-10-17 04:31:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
int numVertex[110];
int islands[110][110][4];
int flights[110][4][5];
double limit = numeric_limits<double>::max();
bool estaEntreRectas(double x, double y, double xB, double yB, double xE, double yE) {
double y1, y2;
if (yE == yB)
return (min(xB,xE) <= x && x <= max(xB,xE));
else if (xE == xB)
return (min(yB,yE) <= y && y <= max(yB,yE));
else{
double m = (yE-yB)/(xE-xB);
double m1 = -(1/m);
double b1 = yB - m1*xB;
double b2 = yE - m1*xE;
y1 = m1 * x + b1;
y2 = m1 * x + b2;
return (min(y1,y2) <= y && y <= max(y1,y2));
}
}
double angleFtV(int indexF,int x,int y){
int v[3] = {flights[indexF][1][0]-flights[indexF][0][0],flights[indexF][1][1]-flights[indexF][0][1],0};
int u[3] = {x-flights[indexF][0][0],y-flights[indexF][0][1],0};
int i = (v[1]*u[2]-v[2]*u[1]);
int j = -(v[0]*u[2]-v[2]*u[0]);
int k = (v[0]*u[1]-v[1]*u[0]);
double num = sqrt(i*i + j*j + k*k);
double denom = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
double opposite = num/denom;
double vPu = v[0]*u[0]+v[1]*u[1]+v[2]*u[2];
double magVPow = v[0]*v[0]+v[1]*v[1]+v[2]*v[2];
double t;
if (v[0]!=0)
t = ((flights[indexF][0][0]+(vPu/magVPow)*v[0])-flights[indexF][0][0])/v[0];
else
t = ((flights[indexF][0][1]+(vPu/magVPow)*v[1])-flights[indexF][0][1])/v[1];
double adyacent = flights[indexF][0][2]+((flights[indexF][1][2]-flights[indexF][0][2])*t);
double angle = atan(opposite/adyacent);
return (angle * 180.0) / M_PI;
}
double minAngleToIsland(int indexI){
double minAngle = limit;
for (int i = 0 ; i < m; i++){
int x1 = flights[i][0][0]; int y1 = flights[i][0][1];
int x2 = flights[i][1][0]; int y2 = flights[i][1][1];
int verify = true;
double maxAngleToFlight = 0;
for (int vertex = 0; vertex < numVertex[indexI];vertex++){
double actualAngle = angleFtV(i,islands[indexI][vertex][0],islands[indexI][vertex][1]);
if (actualAngle > maxAngleToFlight)
maxAngleToFlight = actualAngle;
if (!estaEntreRectas(islands[indexI][vertex][0],islands[indexI][vertex][1],x1,y1,x2,y2))
verify = false;
}
if (verify && minAngle > maxAngleToFlight)
minAngle = maxAngleToFlight;
}
return minAngle;
}
double minAngle(){
double maxAngle = 0;
for (int i = 0 ;i < n;i++){
double minToIsland = minAngleToIsland(i);
if (minToIsland > maxAngle)
maxAngle = minToIsland;
}
if (maxAngle == limit)
maxAngle = -1;
return maxAngle;
}
int main(){
cin>>n>>m;
for(int i = 0; i < n;i++){
cin>>numVertex[i];
for (int j = 0; j < numVertex[i];j++)
cin>>islands[i][j][0]>>islands[i][j][1];
}
for(int i = 0; i < m;i++){
cin>>flights[i][0][0]>>flights[i][0][1]>>flights[i][0][2]>>flights[i][1][0]>>flights[i][1][1]>>flights[i][1][2];
}
double res = minAngle();
if (res==-1){
cout<<"impossible"<<endl;
}
else{
cout<<fixed<<setprecision(9)<<res<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4208kb
input:
1 1 3 -5 0 5 0 0 5 -10 10 10 10 10 10
output:
45.000000000
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 4204kb
input:
1 1 3 -5 0 5 0 0 5 -10 0 10 10 0 10
output:
26.565051177
result:
ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 4180kb
input:
1 1 3 -5 0 5 0 0 5 0 10 10 10 0 10
output:
46.686143342
result:
ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 4204kb
input:
1 1 3 -5 0 5 0 0 5 0 10 5 10 0 10
output:
59.491041134
result:
ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 4152kb
input:
1 1 3 -5 0 5 0 0 5 0 10 20 -10 0 10
output:
31.219698447
result:
ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 4148kb
input:
1 3 3 -5 0 5 0 0 5 -10 0 25 10 0 20 -5 10 10 10 -5 20 -4 1 100 5 10 100
output:
12.528807709
result:
ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 4016kb
input:
1 2 4 0 0 20 0 20 40 0 40 -10 30 30 30 30 30 -10 10 30 30 10 30
output:
45.000000000
result:
ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 4176kb
input:
1 4 4 0 0 20 0 20 40 0 40 -10 30 30 30 30 30 -10 20 30 30 20 30 -10 10 30 30 10 30 10 -10 30 10 50 30
output:
18.434948823
result:
ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
1 2 4 0 0 40 0 40 40 0 40 10 10 10 20 20 20 30 10 10 10 30 20
output:
impossible
result:
ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
1 3 4 0 0 20 0 20 40 0 40 -10 30 30 15 30 30 5 30 30 30 30 30 1 50 30 21 50 30
output:
impossible
result:
ok
Test #11:
score: 0
Accepted
time: 0ms
memory: 4176kb
input:
1 1 4 0 0 40 0 40 40 0 40 -100 -100 20 100 100 10
output:
63.665752153
result:
ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 4172kb
input:
1 4 4 -10 -10 10 -10 10 10 -10 10 -100 0 10 100 0 10 0 100 10 0 -100 10 50 50 15 -50 -50 15 -50 50 15 50 -50 15
output:
43.313856658
result:
ok
Test #13:
score: -100
Wrong Answer
time: 1ms
memory: 3832kb
input:
1 100 100 822286 0 856789 53904 986567 124632 629039 119995 732157 187986 691605 224716 728650 288493 591087 278144 801573 440668 425257 269876 614456 446428 424157 350893 645680 606334 406524 432904 545628 659551 359831 495265 367048 578376 251435 457360 319990 680014 336526 849968 214009 658652 23...
output:
impossible
result:
wrong answer