uvalive 7366(二分 + 两向量的交点 + 向量的旋转)
2017-10-23 21:31
288 查看
题意:给出一个三角形的三个点,然后求使得图中的三个角相等的三角形内的点的坐标。
思路:因为有单调性,所以对角进行二分,然后用两个角求出第三个角,看是否符合。
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
typedef struct Node
{
double x,y;
Node operator - (Node t)
{
return (Node){x - t.x,y - t.y};
}
Node operator + (Node t)
{
return (Node){x + t.x,y + t.y};
}
//点积
double operator * (Node t)
{
return x * t.x + y * t.y;
}
//叉积
double operator ^(Node t)
{
return x * t.y - y*t.x;
}
Node operator * (double t)
{
return (Node){x * t,y * t};
}
}Vector;
double Angle(Vector p1,Vector p2)
{
return acos( (p1 * p2) / sqrt(p1 *p1) / sqrt(p2 * p2));
}
Vector Lrotate(Vector p,double angle)//逆时针旋转
{
return (Vector){p.x * cos(angle) - p.y * sin(angle) ,p.x * sin(angle) + p.y * cos(angle)};
}
Vector Rrotate(Vector p,double angle)//顺时针旋转
{
return (Vector){p.y * sin(angle) - p.x * cos(angle) ,p.x * sin(angle) + p.y * cos(angle)};
}
Node GetIn(Node P,Vector v,Node Q,Vector w) //两直线的交点
{
Vector u = P - Q;
double t = (w^u)/(v^w);
return P+v*t;
}
Node a[3];
Node s;
double get(double angle)
{
Vector p1 = Lrotate(a[2] - a[1],angle),p2 = Lrotate(a[1] - a[0],angle);
s = GetIn(a[0],p2,a[1],p1);
return Angle(s - a[2],a[0] - a[2]);
}
int main()
{
// freopen("in.txt","r",stdin);
int Tcase;scanf("%d",&Tcase);
while(Tcase --)
{
int k;scanf("%d",&k);
for(int i = 0; i < 3;i ++)scanf("%lf%lf",&a[i].x,&a[i].y);
double l = 0,r = PI/2;
r = min(r,Angle(a[1] - a[0],a[2] - a[0]));
r = min(r,Angle(a[2] - a[1],a[0] - a[1]));
r = min(r,Angle(a[0] - a[2],a[1] - a[2]));
while(r - l > 1e-10)
{
double mid = (l + r) / 2;
if(get(mid) > mid) l = mid;
else r = mid;
}
printf("%d %.5f %.5f\n",k,s.x,s.y);
}
return 0;
}
相关文章推荐
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
- UVa11178 - Morley's Theorem(向量旋转+直线交点)
- UVA 11178 || Morley's Theorem (向量旋转求交点
- UVALive 3211 Now or later(2-SAT,二分,Kosaraju)
- UVAlive 6611 Alice's Print Service 二分
- uvalive 3635 - Pie(二分搜索)
- UVALive - 3027 Corporative Network 并查集+向量
- UVALive 7261 Xiongnu's Land(二分)
- UVA 11178 旋转边求交点
- UVALive 3177 长城守卫(贪心+二分)
- UVALive 6525 Attacking rooks 二分匹配 经典题
- Clock Splitter+uvalive+二分
- Uvalive 4728 Squares(旋转卡壳)
- UVALIVE 5000 Underwater Snipers(二分+贪心)
- UVALive - 4254 Processor 二分+优先队列
- uvalive 4725(贪心 + 二分)
- uvalive 2949 - Elevator Stopping Plan(贪心+二分)
- POj 2002 UVALive - 3047 C - Squares 【计算几何+二分求解】
- uva 1421 & uvalive 4253 Archery(二分)
- UVALive 5000 Underwater Snipers --二分