标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1232 Accepted Submission(s): 545
Special Judge
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define CT continue
#define SC scanf
const double eps=1e-8;
const double pi=acos(-1);
int cas,n;
struct Point{
double x,y,pi;
void read(){
SC("%lf%lf%lf",&x,&y,&pi);
}
}p[15];
int dcmp(double a)
{
if(fabs(a)<eps) return 0;
else return a>0?1:-1;
}
double dot(Point a,Point b)
{
return a.x*b.x+a.y*b.y;
}
double Length(Point a)
{
return sqrt(a.x*a.x+a.y*a.y);
}
Point operator*(double k,Point a)
{
return (Point){k*a.x,k*a.y,0};
}
Point operator-(Point a,Point b)
{
return (Point){a.x-b.x,a.y-b.y,0};
}
Point operator+(Point a,Point b)
{
return (Point){a.x+b.x,a.y+b.y,0};
}
Point Rotate(Point a,double rad)
{
return (Point){a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad),0};
}
Point Normal(Point a)
{
double L=Length(a);
return (Point){-a.y/L,a.x/L,0};
}
void R(Point &s,Point &t,Point &nor,Point &mid)
{
s=p[0];
for(int i=1;i<=n;i++){
Point v=p[0]-p[i];
v=Rotate(v,p[i].pi);
p[0]=p[i]+v;
}
t=p[0];
nor=Normal(t-s),mid=(Point){(s.x+t.x)/2,(s.y+t.y)/2,0};
}
double cross(Point a,Point b)
{
return a.x*b.y-b.x*a.y;
}
Point Getlineintersection(Point p,Point v,Point q,Point w)
{
Point u=p-q;
double t=cross(w,u)/cross(v,w);
return p+t*v;
}
int main()
{
SC("%d",&cas);
while(cas--)
{
SC("%d",&n);
for(int i=1;i<=n;i++) p[i].read();
Point s1,t1,s2,t2,nor1,nor2,mid1,mid2,o;
p[0]={12,9,0};
R(s1,t1,nor1,mid1);
p[0]={3,17,0};
R(s2,t2,nor2,mid2);
o=Getlineintersection(mid1,nor1,mid2,nor2);
Point os=s1-o,ot=t1-o;
double ang,ang1=atan2(os.y,os.x),ang2=atan2(ot.y,ot.x);
if(dcmp(ang1-ang2)>0) ang=ang1-ang2;
else ang=ang2-ang1;
if(dcmp(cross(t1-s1,o-s1))>0){
if(dcmp(ang-pi)>0) ang=2*pi-ang;
}
else {
if(dcmp(pi-ang)>0) ang=2*pi-ang;
}
if(dcmp(o.x)==0) o.x=0;
if(dcmp(o.y)==0) o.y=0;
printf("%.10f %.10f %.10f\n",o.x,o.y,ang);
}
return 0;
}
1.因为题目保证有解,所以在平面上任取两点,求出旋转后的弧度,那么最后选装的圆心必定在两条
从起点到终点的中垂线上
2.找到圆心后,再依据圆心在向量st的左侧还是右侧确定旋转的弧度是>pi还是小于pi。
3.最后因为double表示数据时,0可能是2*1e-30,按%.10f输出则是-0.00000000,所以需要
在最后判断一下。
标签:
原文地址:http://www.cnblogs.com/smilesundream/p/5932239.html