题意:
给你n次折叠
m个询问
每次询问折叠后,xi,yi有几层
题解:
计算几何
模拟
#include<cstdio> #include<cstdlib> #include<cmath> using namespace std; int n,m; double px[15],py[15],qx[15],qy[15]; int dcmp(double a,double b) { if (fabs(a-b)<=1e-9) return 0; if (a<b)return -1; return 1; } double Cross(double x1,double y1,double x2,double y2) { return x1*y2-x2*y1; } void calc(double x1,double y1,double x0,double y0,double &retx,double &rety) { retx=(x0*(x1*x0+y1*y0)+y0*(x0*y1-x1*y0))/(x0*x0+y0*y0); rety=(y0*(x1*x0+y1*y0)-x0*(x0*y1-x1*y0))/(x0*x0+y0*y0); } int dp(double x,double y,int t) { if (!t) { if (dcmp(x,100.0)<0&&dcmp(x,0.0)>0&&dcmp(y,100.0)<0&&dcmp(y,0.0)>0) return 1; return 0; } if (dcmp(Cross(x-px[t],y-py[t],qx[t]-px[t],qy[t]-py[t]),0.0)>=0)return 0; else { double retx,rety; calc(x-px[t],y-py[t],qx[t]-px[t],qy[t]-py[t],retx,rety); retx+=px[t];rety+=py[t]; return dp(x,y,t-1)+dp(retx,rety,t-1); } } int main() { double _x,_y; scanf("%d",&n); for (int i=1;i<=n;i++)scanf("%lf%lf%lf%lf",&px[i],&py[i],&qx[i],&qy[i]); scanf("%d",&m); while (m--) { scanf("%lf%lf",&_x,&_y); printf("%d\n",dp(_x,_y,n)); } return 0; }