题意:一只狗被拴在杆子上,从起点开始按直线依次跑到给出的点最后回到起点问绕杆子几圈,逆时针为正,顺时针为负,撞到杆子输出Ouch!。

解法:用叉积判断方向,用余弦定理求出以杆子为顶点的角,加和除以2π,最后的答案处理因为精度问题wa了一篇orz……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
const double eps = 1e-;
struct node
{
double x, y;
} point[];
double cross(node p1, node p2, node p3)//叉积
{
return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
}
double len(node p1, node p2)//两点长度的平方
{
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}
double cal(node p1, node p2, node p3)//余弦定理
{
double a = len(p2, p3), b = len(p1, p3), c = len(p1, p2);
return acos((b + c - a) / 2.0 / sqrt(b * c));
}
int line(node p1, node p2, node p3)//判断叉积为0时杆是否在两点中间
{
return p3.x >= min(p1.x, p2.x) && p3.x <= max(p1.x, p2.x) && p3.y >= min(p1.y, p2.y) && p3.y <= max(p1.y, p2.y);
}
int main()
{
int n;
while(~scanf("%d", &n) && n)
{
node pole;
scanf("%lf%lf", &pole.x, &pole.y);
for(int i = ; i < n; i++)
scanf("%lf%lf", &point[i].x, &point[i].y);
double degree = 0.0;
int ans = ;
for(int i = ; i < n - ; i++)
{
double flag = cross(pole, point[i], point[i + ]);
double res = cal(pole, point[i], point[i + ]);
if((fabs(flag) <= eps) && line(point[i], point[i + ], pole))
{
ans = ;
break;
}
else if(flag > eps)
degree += res;
else if(flag < -eps)
degree -= res;
else
{
if(line(point[i], point[i + ], pole))
{
ans = ;
break;
}
}
}
double flag = cross(pole, point[n - ], point[]);
double res = cal(pole, point[n - ], point[]);
if((fabs(flag) <= eps) && line(point[n - ], point[], pole))
ans = ;
else if(flag > eps)
degree += res;
else if(flag < -eps)
degree -= res;
else if(line(point[n - ], point[], pole))
ans = ;
if(ans)
{
printf("Ouch!\n");
continue;
}
degree = degree * 0.5 / acos(-1.0);
char x[];
sprintf(x, "%.0lf", degree);
sscanf(x, "%d", &ans);
if(ans > )
printf("+");
printf("%d\n", ans);
}
return ;
}

UVA 11928 The Busy Dog的更多相关文章

  1. UVa 二分图匹配 Biginners

    UVa 1045 - The Great Wall Game 最小权匹配 题意:给你一个n*n的棋盘,上面有n个棋子,要求通过移动各个棋子使得棋子在同一行或者同一列或者对角线上,求最小移动次数. 思路 ...

  2. 二分图最大匹配(匈牙利算法) UVA 670 The dog task

    题目传送门 /* 题意:bob按照指定顺序行走,他的狗可以在他到达下一个点之前到一个景点并及时返回,问狗最多能走多少个景点 匈牙利算法:按照狗能否顺利到一个景点分为两个集合,套个模板 */ #incl ...

  3. ●UVA 11796 Dog Distance

    题链: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  4. UVA 11796 Dog Distance(几何)

    Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...

  5. UVA 11796 - Dog Distance 向量的应用

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  6. 简单几何(相对运动距离最值) UVA 11796 Dog Distance

    题目传送门 题意:两只狗在折线上跑,速度未知,同时出发,同时达到.问跑的过程中,两狗的最大距离和最小距离的差 分析:训练指南P261,考虑相对运动,设A静止不动,B相对A运动,相对的运动向量:Vb - ...

  7. UVA 11796 - Dog Distance

    题意  两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法  恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...

  8. UVA 11796 Dog Distance(向量)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...

  9. 转:Busy Developers' Guide to HSSF and XSSF Features

    Busy Developers' Guide to Features Want to use HSSF and XSSF read and write spreadsheets in a hurry? ...

随机推荐

  1. mysql 连接丢失错误解决(转载)

    1.1 错误信息: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet succes ...

  2. 然爸读书笔记(2013-4)----打造facebook

    扎克伯格的真实一面 (1)在公司内部知无不言,扎克伯格在公司内部问答时间.尽可能回答员工的任何问题,保持足够的透明度. (2)员工只有做到对外守口如瓶,我们才能做到对内知无不言. (3)faceboo ...

  3. iOS 网络编程

    iOS 开发中所需的数据基本都是来自网络,网络数据请求是 iOS 编程中必不可少的,应该熟练掌握网络请求. 网络请求方式有 :GET , POST , PUT ,DELETE 等,其中常用的就是 GE ...

  4. 对象工具类 - ObjectUtils.java

    对象工具类,提供对象克隆.获取对象属性.类型判断.Map转换对象.对象转Map.设置对象属性等. 源码如下:(点击下载 -  ObjectUtils.java .JsonUtils.java .gso ...

  5. mysql 获取季度的第一天 本月的第一天,本周的第一天sql语句(转)

    感谢:http://www.111cn.net/database/110/d45124323da8d2d87b80f78319987eda.htm 查看同主题的另一篇博客:http://blog.cs ...

  6. FaceNet--Google的人脸识别(转)

    引入 随着深度学习的出现,CV领域突破很多,甚至掀起了一股CV界的创业浪潮,当次风口浪尖之时,Google岂能缺席.特贡献出FaceNet再次刷新LFW上人脸验证的效果记录. 本文是阅读FaceNet ...

  7. SetTimer在无窗口和有窗口线程的使用 . .

    今天犯了一个粗心的错误,在无窗口线程中,SetTimer中设置计时器ID,而WM_TIMER消息响应函数中得到的计时器ID却不是之前设置的计时器ID. 对应计时器ID的输出的是一个随机数字. 原来在m ...

  8. 【leetcode】Dungeon Game (middle)

    The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...

  9. maven3常用命令\创建Project

    转自 http://blog.csdn.net/edward0830ly/article/details/8748986 ------------------------------maven3常用命 ...

  10. 使用FileZilla Server轻松搭建个人FTP服务器

    Linux平台下快速搭建FTP服务器 服务器FTP Server环境搭建 针对以上遇到的问题的解决方案如下: 1)如何上传文件到云服务器上          关于这个问题,我首先想到的是使用FileZ ...