Pegasus Circle Shortcut(计算几何)

题目链接:https://ac.nowcoder.com/acm/contest/12794/I
已知三点坐标:A (X1,Y1) B (X2,Y2) C (X3,Y3)
AB向量:(X2-X1,Y2-Y1)
AC向量:(X3-X1,Y3-Y1)
BC向量:(X3-X2,Y3-Y2)
COS∠A=[(X2-X1)(X3-X1)+(Y2-Y1)(Y3-Y1)]/|AB||AC|
其中:|AB|=[(X2-X1)2+(Y2-Y1)2]^0.5
|AC|=[(X3-X1)2+(Y3-Y1)2]^0.5
∠A = Arccos {[(X2-X1)(X3-X1)+(Y2-Y1)(Y3-Y1)]/|AB||AC|}
利用矢量叉乘判断正负
a x b = |a| * |b| * sin();

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack> 
#include <cmath>
using namespace std;

const int maxn = 500000 + 5;
const int INF = 0x3f3f3f3f;
const double esp = 0.001;
const double pi = 3.1415926;

double xc,yc,xs,ys,xf,yf;

double dis(double x1, double y1, double x2, double y2) {
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main() {
    int cnt = 0;
    while(++cnt) {
        cin >> xc >> yc >> xs >> ys >> xf >> yf;
        if(xc == 0 && yc == 0 && xs == 0 &&
            ys == 0 && xf == 0 && yf == 0) break;
        double xcs = xs - xc, ycs = ys - yc;
        double xcf = xf - xc, ycf = yf - yc;
        double _cs = sqrt(xcs * xcs + ycs * ycs);
        double _cf = sqrt(xcf * xcf + ycf * ycf);
        double cos_scf = (xcs * xcf + ycs * ycf) / (_cs * _cf);
        double sin_scf = (xcs * ycf - xcf * ycs) / (_cs * _cf);
        double _scf = (sin_scf > 0 ? 1 : -1) * fabs(acos(cos_scf));
        double x1 = xs, y1 = ys, x2, y2;
        int n;
        cin >> n;
        double _d1 = 0.0;
        for(int i = 1; i <= n; ++i) {
            cin >> x2 >> y2;
            _d1 += dis(x1,y1,x2,y2);
            x1 = x2, y1 = y2;
        }
        _d1 += dis(x1,y1,xf,yf);
        double r = dis(xs,ys,xc,yc);
        if(_scf < 0) _scf += 2 * pi;
        double _d2 = r * _scf;
        cout << "Case #" << cnt;
        if(_d1 <= _d2) {
            cout << ": Watch out for squirrels!" << endl << endl;
        }
        else if(_d2 < _d1) {
            cout << ": Stick to the Circle." << endl << endl;
        }
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值