题目大意:给定n,要求构造一个凸n边形,使得每个内角都相同,每条边长度都不同
其实我一开始想的是构造一个正n边形然后把每条边微移一下……不过似乎不是很好写的样子= =
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 110
#define PI 3.1415926535897932
using namespace std;
struct Point{
double x,y;
Point() {}
Point(double _,double __):
x(_),y(__) {}
friend Point operator + (const Point &p1,const Point &p2)
{
return Point(p1.x+p2.x,p1.y+p2.y);
}
friend Point operator - (const Point &p1,const Point &p2)
{
return Point(p1.x-p2.x,p1.y-p2.y);
}
friend double operator * (const Point &p1,const Point &p2)
{
return p1.x*p2.y-p1.y*p2.x;
}
friend Point operator * (const Point &p,double rate)
{
return Point(p.x*rate,p.y*rate);
}
friend Point Rotate (const Point &p,double alpha)
{
return Point(p.x*cos(alpha)-p.y*sin(alpha),p.x*sin(alpha)+p.y*cos(alpha) );
}
}ans[M];
struct Line{
Point p,v;
Line() {}
Line(const Point &_,const Point &__):
p(_),v(__) {}
friend Point Get_Intersection(const Line &l1,const Line &l2)
{
Point u=l1.p-l2.p;
double temp=(l2.v*u)/(l1.v*l2.v);
return l1.p+l1.v*temp;
}
};
int n;
int main()
{
int i;
cin>>n;
if(n<=4)
return cout<<"No solution"<<endl,0;
Point v(-1,0);
double len=450.0,delta=0.005;
double alpha=2.0*PI/n;
for(i=1;i<n;i++)
{
ans[i]=ans[i-1]+v*len;
len+=delta;
v=Rotate(v,-alpha);
}
ans[n]=Get_Intersection(Line(ans[n-1],v),Line(Point(0,0),Point(1,0)));
for(i=n;i;i--)
printf("%.10lf %.10lf\n",ans[i].x,ans[i].y);
return 0;
}
时间: 2024-10-09 04:12:14