QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#39254 | #237. Triangle Partition | wyhao | WA | 121ms | 1808kb | C++ | 1.2kb | 2022-07-09 10:22:27 | 2022-07-09 10:22:28 |
Judging History
answer
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=3005;
int T,n,m;
struct node{
int x,y,id;
}A[N];
bool cmp(node a,node b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
bool vis[N];
int stk[N],tot;
bool check(int i,int j,int k){
return 1ll*(A[j].y-A[i].y)*(A[k].x-A[j].x)<1ll*(A[k].y-A[j].y)*(A[j].x-A[i].x);
}
double get1(int i,int j,int k){
double x1=A[i].x-A[j].x,y1=A[i].y-A[j].y;
double x2=A[k].x-A[j].x,y2=A[k].x-A[j].y;
return (x1*x2+y1*y2)/sqrt(x1*x1+y1*y1)/sqrt(x2*x2+y2*y2);
}
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);m=3*n;
for(int i=1;i<=m;i++){
scanf("%d%d",&A[i].x,&A[i].y);
vis[i]=false;A[i].id=i;
}
sort(A+1,A+m+1,cmp);
while(n--){
tot=0;
for(int i=1;i<=m;i++){
if(vis[i]) continue;
while(tot>1 and !check(stk[tot-1],stk[tot],i)) tot--;
stk[++tot]=i;
}
vis[stk[1]]=vis[stk[2]]=true;
printf("%d %d ",A[stk[1]].id,A[stk[2]].id);
int mi;double mm=-1;
for(int i=1;i<=m;i++){
if(vis[i]) continue;
double mk=get1(stk[1],stk[2],i);
if(mk>mm){
mi=i;
mm=mk;
}
}
vis[mi]=true;
printf("%d\n",A[mi].id);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 121ms
memory: 1808kb
input:
190 10 -7215 2904 -5179 1663 -542 1091 -5687 7868 7838 -1048 -2944 4346 -2780 3959 -9402 1099 -8548 -7238 -3821 -2917 2713 295 -856 -8661 7651 3945 -8216 -543 5798 5024 8583 -3384 -1208 5955 3068 -385 340 2968 6559 -272 4537 5075 5126 4343 639 8281 1700 2572 819 9317 -9854 -1316 -3421 -1137 9368 718...
output:
26 9 28 8 14 16 29 12 10 1 27 5 4 2 13 6 7 30 17 3 20 19 18 24 23 11 21 25 22 15 30 3 1 18 29 21 5 25 27 17 12 26 11 9 10 15 13 24 19 6 7 28 22 8 23 4 14 2 20 16 6 11 28 16 10 27 8 19 29 13 7 9 15 14 21 22 20 2 18 3 24 12 26 1 4 5 30 25 23 17 16 18 30 8 24 28 19 13 4 23 7 20 26 25 3 1 27 5 29 12 9 6...
result:
wrong answer intersect