几何——BAPC2019 K
感觉这题思路简单,其实就是解一个二元一次方程组
#include<bits/stdc++.h> using namespace std; #define N 20 int x[N],y[N],n; double xa,xb,xc,ya,yb,yc,X,Y; int main(){ cin>>n>>X>>Y; for(int i=1;i<=n;i++) cin>>x[i]>>y[i]; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) for(int k=j+1;k<=n;k++){ double a,b,c; xa=x[i],ya=y[i]; xb=x[j],yb=y[j]; xc=x[k],yc=y[k]; if(xa!=xc){ double tmp=Y-yc-(ya-yc)*(X-xc)/(xa-xc); if(tmp==0){ b=0,a=(X-xc)/(xa-xc); }else { b=tmp/(yb-yc-(ya-yc)*(xb-xc)/(xa-xc)); a=(X-xc)/(xa-xc)-(xb-xc)/(xa-xc)*b; } }else {//xa==xc b=(X-xc)/(xb-xc); a=(Y-yc-b*(yb-yc))/(ya-yc); } c=1-a-b; if(a>=0 && b>=0 && c>=0){ for(int l=1;l<=n;l++){ if(l==i)printf("%.10lf\n",a); else if(l==j)printf("%.10lf\n",b); else if(l==k)printf("%.10lf\n",c); else cout<<0<<'\n'; } return 0; } } }