给一个矩形,和矩形上一点,用过这个点的n-1条直线将这个矩形分成等面积的n份,求这n-1个交点
只用到叉积求面积和二分答案求长度就够了...
#include <cstdio>
#include <cstring>
using namespace std;
struct Point {
double x,y;
Point() {}
Point(double xx,double yy) {
x=xx;y=yy;
}
void print() {
printf("%.3lf %.3lf ",x,y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x-b.x,a.y-b.y);
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x+b.x,a.y+b.y);
}
friend Point operator * (const Point &a,double b) {
return Point(a.x*b,a.y*b);
}
friend double crossMul(const Point &a,const Point &b) {
return b.x*a.y-a.x*b.y;
}
};
struct Segment {
Point s,t;
Segment() {}
Segment(Point ss,Point tt) {
s=ss;t=tt;
}
operator Point () {
return t-s;
}
};
int w,h,d,n;
double s,curs;
double calS(Point a,Point b,Point c) {
return curs-0.5*crossMul(b-a,c-b);
}
Point cal(Point door,Point tmp1,Point tmp2) {
double l=0,r=1;
Point ans;
while (r-l>1e-9) {
double t=(l+r)/2;
ans=tmp1+(tmp2-tmp1)*t;
/*
printf("!! \n!!");
printf("%lf\n",t);
((tmp2-tmp1)*t).print();
ans.print();
printf("\n");
printf("!! %lf %lf\n",t,calS(door,tmp1,ans));
*/
if (calS(door,tmp1,ans)<s) l=t;
else r=t;
}
curs=0;
ans=tmp1+(tmp2-tmp1)*l;
return ans;
}
int main() {
Point door,tmp1,tmp2;
while (scanf("%d%d%d%d",&w,&h,&d,&n),n!=0) {
curs=0;
s=(double)w*h/n;
door=Point(d,0);
tmp1=Point(w,0);
tmp2=Point(w,h);
while (calS(door,tmp1,tmp2)>=s) {
tmp1=cal(door,tmp1,tmp2);
tmp1.print();
/*
printf("\n--test--\n");
door.print();
tmp1.print();
tmp2.print();
printf("\n--test over--\n");
getchar();
*/
}
curs=calS(door,tmp1,tmp2);
tmp1=Point(w,h);
tmp2=Point(0,h);
while (calS(door,tmp1,tmp2)>=s) {
tmp1=cal(door,tmp1,tmp2);
tmp1.print();
/*
printf("\n--test--\n");
door.print();
tmp1.print();
tmp2.print();
printf("\n--test over--\n");
getchar();
*/
}
curs=calS(door,tmp1,tmp2);
tmp1=Point(0,h);
tmp2=Point(0,0);
while (calS(door,tmp1,tmp2)>=1.5*s) {
tmp1=cal(door,tmp1,tmp2);
tmp1.print();
/*
printf("\n--test--\n");
door.print();
tmp1.print();
tmp2.print();
printf("\n--test over--\n");
getchar();
*/
}
printf("\n");
}
return 0;
}