问题
https://vjudge.net/problem/UVA-10609
分析
分形。
就是在每个边上擦去中间的1/2部分,然后画上突出的三角形。
注意dfs的时候,不要把点的顺序写反了,是dfs(x5,y5,x4,y4),不是dfs(x4,y4,x5,y5)。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
const int maxn=100000+5;
const double eps=1e-8,coef=sqrt(3.0)/4;
struct Point{
double x,y;
Point(double x=0,double y=0):x(x),y(y){}
bool operator < (const Point &rhs) const {
if(x<rhs.x-eps || x>rhs.x+eps) return x<rhs.x-eps;
return y<rhs.y-eps;
}
};
set<Point> rec;
double T;
//增加3个点C,D,E
void dfs(double x1,double y1,double x2,double y2){
if((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)<4*T*T) return;
double x3=x1+(x2-x1)/4,x4=x1+3*(x2-x1)/4,y3=y1+(y2-y1)/4,y4=y1+3*(y2-y1)/4;
double x5=(x1+x2)/2+coef*(y1-y2),y5=(y1+y2)/2+coef*(x2-x1);
rec.insert(Point(x3,y3));
rec.insert(Point(x4,y4));
rec.insert(Point(x5,y5));
dfs(x3,y3,x5,y5);
dfs(x5,y5,x4,y4);
}
int kase=0;
double x,y,x2,y2;
int main(void){
while(scanf("%lf%lf%lf%lf%lf",&x,&y,&x2,&y2,&T)==5 && T>1-eps){
rec.clear();
rec.insert(Point(x,y));
rec.insert(Point(x2,y2));
dfs(x,y,x2,y2);
printf("Case %d:\n",++kase);
printf("%d\n",rec.size());
for(auto it=rec.begin();it!=rec.end();++it){
printf("%.5lf %.5lf\n",it->x,it->y);
}
}
return 0;
}