竞赛讨论区 > 四等分的角度
头像
spnooyseed
发布于 2020-05-02 13:19
+ 关注

四等分的角度

求解我的做法为啥只过了50%的样例,
下面是做法原理;
根据矩阵变换公式
图片说明

图片说明

图片说明
我将B点根据旋转公式旋转一次旋转图片说明 得到 k1 , k2 , k3

然后我就先写程序找到A、B点中靠右的点即可以逆时针旋转的点
然后根据公式旋转,

50%的样例真难受 , 应该是我代码某个地方错了,找不出来, 求帮助

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<double , double> PII ;
const int N = 1e5 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int in()
{
  int x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
#define x first
#define y second
double dis(PII a , PII b)
{
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) ;
}
double get(PII a , PII o , PII b)
{
  double ao = dis(a , o) , ab = dis(a , b) , bo = dis(b , o) ;
  double oo = acos((ao * ao + bo * bo - ab * ab) / (2 * ao * bo)) ;
  return oo ;
}
double oo ;
PII solve(PII a , double oo)
{
  double x = cos(oo) * a.x - sin(oo) * a.y ;
  double y = sin(oo) * a.x + cos(oo) * a.y ;
  return {x , y} ;
}
int main()
{
  PII a , o , b ;
  cin >> a.x >> a.y >> o.x >> o.y >> b.x >> b.y ;
  PII x = o ;
  a.x -= o.x , a.y -= o.y  , b.x -= o.x , b.y -= o.y ;
  o.x -= o.x , o.y -= o.y ;
  oo = get(a , o , b) ;
  PII ans ;
  if((a.y >= 0 && b.y >= 0) || (a.y <= 0 && b.y <= 0))
     {
       if(a.y >= 0 && b.y >= 0)
        {
         if(get(a , o , {1 , 0}) > get(b , o , {1 , 0})) ans = b ;
         else ans = a ;
        }
       else
        {
          if(get(a , o , {1 , 0}) < get(b , o , {1 , 0})) ans = b ;
          else ans = a ;
        }
     }
  else
   {
     if(a.y > 0)
      {
        if(get(b , o , {1 , 0}) > get({-a.x , -a.y} , o , {1 , 0})) ans = a ;
        else ans = b ;
      }
     else if(b.y > 0)
      {
        if(get(a , o , {1 , 0}) > get({-b.x , -b.y} , o , {1 , 0})) ans = b ;
        else ans = a ;
      }
   }

  PII res = solve(ans , oo * 3 / 4) ;
  printf("%.12lf %.128lf\n" , res.x + x.x, res.y + x.y) ;
  res = solve(ans , oo / 2) ;
  printf("%.12lf %.12lf\n" , res.x + x.x, res.y + x.y) ;
  res = solve(ans , oo  / 4) ;
  printf("%.12lf %.12lf\n" , res.x + x.x, res.y + x.y) ;
  return 0 ;
}
/*
*/

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐