QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#185865 | #7065. Triangle | linnins | AC ✓ | 866ms | 1652kb | C++20 | 3.5kb | 2023-09-22 18:01:02 | 2023-09-22 18:01:03 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define EMS 1e-7
int xx = 0;
int read_int(){
char c;
while(((c = getchar()) < '0' || c > '9') && c != '-');
bool flag = false;
int x = 0;
if(c == '-')
flag = true;
else
x = c - '0';
while((c = getchar()) >= '0' && c <= '9')
x = x * 10 + c - '0';
if(flag)
return -x;
return x;
}
double Fabs(double a){
if(a<0)
return a* -1;
else
return a;
}
struct Node{
double x,y;
void print(){
printf("%.8lf %.8lf\n",x,y);
}
};
void Swap(Node *a,Node *b){
Node c;
c = *a;
*a = *b;
*b = c;
}
int check(Node a,Node b,Node end){
if((end.y - b.y) * (b.x - a.x) >= (b.y - a.y) * (end.x - b.x) - EMS && (end.y - b.y) * (b.x - a.x) <= (b.y - a.y) * (end.x - b.x) + EMS && ((end.x <= a.x && end.x >= b.x) || end.x >= a.x && end.x <= b.x))
return 1;
else
return 0;
}
double cal(Node a,Node b,Node c){
return (b.y - (c.y - b.y) * (b.x - a.x) / (c.x - b.x));//求 a 投影在bc的y坐标
}
void mapping(Node *a,Node *b,Node *c){
swap(a->x,a->y);
swap(b->x,b->y);
swap(c->x,c->y);
}
Node find(Node Const,Node b,Node P,double Area){
double L = min(Const.x,b.x);
double R = max(Const.x,b.x);
Node Ans;
while(L < R - EMS){
double Mid = (L+R)/2;
Ans.x = Mid;
Ans.y = cal(Ans,Const,b);
double midAns;
if(b.x >= P.x + EMS || b.x <= P.x - EMS)
midAns = Fabs(cal(Ans,b,P) - Ans.y) * Fabs(b.x-P.x);
else
midAns = Fabs(cal(P,b,Ans) - P.y) * Fabs(Ans.x - b.x);
if(midAns > Area / 2 - EMS && midAns < Area/2 + EMS)
return Ans;
if(midAns <= Area / 2 - EMS)
if(Const.x <= b.x)
R = Mid;
else
L = Mid;
if(midAns >= Area/2 + EMS)
if(Const.x <= b.x)
L = Mid;
else
R = Mid;
}
return Ans;
}
void solve(Node a,Node b,Node P,double Area){
int Mapping = 0;
if(Fabs(a.x - b.x) <= Fabs(a.y - b.y)){
Mapping = 1;
mapping(&a,&b,&P);
}
Node Ans = find(b,a,P,Area);
if(Mapping == 1)
swap(Ans.x,Ans.y);
// if(Ans.x >= 18884 and Ans.x <= 18889)
// printf("%d**\n",xx);
Ans.print();
}
double dis(Node a,Node b){
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
xx += 1;
Node a1,a2,a3,end1,end2;
int Mapping = 0;
double Area = 0;
a1.x = read_int();
a1.y = read_int();
a2.x = read_int();
a2.y = read_int();
a3.x = read_int();
a3.y = read_int();
end1.x = read_int();
end1.y = read_int();
// if(T == 1){
// printf("0.5 0.5\n-1\n");
// return 0;
// }
// if(xx == 105){
// printf("**");
// a1.print();
// a2.print();
// a3.print();
// end1.print();
// }
if(a1.x == a2.x)
Swap(&a1,&a3);
Area = Fabs(cal(a3,a1,a2) - a3.y) * Fabs(a2.x-a1.x);
if(check(a2,a3,end1)){
if(dis(a2,end1) < dis(a3,end1))
solve(a3,a1,end1,Area);
else
solve(a2,a1,end1,Area);
}
else if(check(a1,a3,end1)){
if(dis(a1,end1) < dis(a3,end1))
solve(a3,a2,end1,Area);
else
solve(a1,a2,end1,Area);
}
else if(check(a1,a2,end1)){
if(dis(a1,end1) < dis(a2,end1))
solve(a2,a3,end1,Area);
else
solve(a1,a3,end1,Area);
}
else{
printf("%d\n",-1);
}
}
return 0;
}
/*
2
0 0 1 1 1 0 1 0
0 0 1 1 1 0 2 0
1
0 0 0 3 9 0 6 1
1
7236 0 25164 0 29961 20959 21593 0
1
22010 28633 9925 11283 14054 15210 8021 15836
1
9456 15557 18451 3957 6242 20372 9855 5351
1
30245 31547 9979 4703 25914 19144 26670 11383
1
30502 0 2596 0 2746 12009 6505 0
*/
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1600kb
input:
2 0 0 1 1 1 0 1 0 0 0 1 1 1 0 2 0
output:
0.50000000 0.50000000 -1
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 310ms
memory: 1604kb
input:
999966 9456 15557 18451 3957 6242 20372 9855 5351 30245 31547 9979 4703 25914 19144 26670 11383 13855 0 24614 0 15860 11017 12445 0 27870 17680 4219 3554 9129 29072 28316 17893 3249 27269 12754 4923 31746 16860 14894 21576 6846 0 1915 0 25023 28721 10508 0 10110 11862 23224 10373 17715 8212 29474 11...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 21424.68147948 13086.05391104 -1 -1 18711.23799030 10162.37637723 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 28212.95213489 245.81778624 -1 -1 -1 -1 -1 -1 -1 -1 22604.57530220 14546.12871612 -1 -1 11557.34652184 4668.20979016 -1 -1 ...
result:
ok 1111378 numbers
Test #3:
score: 0
Accepted
time: 317ms
memory: 1652kb
input:
999974 9228 16833 13143 23461 5117 7645 21359 13652 21313 3160 20333 1620 16288 7781 13315 10132 4372 0 27536 0 3207 8695 9983 0 21469 29998 19948 29904 30517 11141 14857 12881 11116 29172 16833 32095 18915 9448 22043 12275 32131 0 14304 0 16638 29018 2048 0 4695 4823 14130 2496 32676 4092 6363 2476...
output:
-1 -1 11482.99037201 5737.22383638 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 15409.84185498 12451.42786361 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 10828.97138576 25347.33485727 -1 -1 -1 -1 -1 18768.67269952 12151.36715094 -1 -1 -1 -1 -1 10801.12059369 5947.86178...
result:
ok 1110866 numbers
Test #4:
score: 0
Accepted
time: 866ms
memory: 1580kb
input:
1000000 54242 34392 23333 92971 5711 47765 54242 34392 24492 41078 36756 68794 2060 62118 14678 50283 12685 18891 59613 23256 26016 46755 59613 23256 85238 49611 95092 85360 45143 87657 95092 85360 72852 37174 39825 60628 32289 18423 72852 37174 95309 61613 1645 45877 78395 38196 95309 61613 92215 7...
output:
14522.00000000 70368.00000000 32900.88888888 68052.22222222 19350.50000000 32823.00000000 65190.50000007 68633.99999993 36056.99999999 39525.49999992 40020.00000000 42036.50000000 95183.50000001 40970.50000008 28582.00000000 94834.50000000 55598.00000000 59174.00000000 19727.00000000 68648.00000000 ...
result:
ok 2000000 numbers