题意:一只狗被拴在杆子上,从起点开始按直线依次跑到给出的点最后回到起点问绕杆子几圈,逆时针为正,顺时针为负,撞到杆子输出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. response 后刷新页面,点击按钮后,禁用该按钮

    一,正常的点击按钮后,将其灰显,全部执行完毕再正常显示. this.btnSave.Attributes.Add("onclick", "if (typeof(Page_ ...

  2. eclipse里maven项目An error occurred while filtering resources解决办法(转载)

    转自:http://liyanjie918.blog.163.com/blog/static/20227290201581143110105/ 在使用eclipse构建maven项目时,突然出现错误提 ...

  3. (转)使用Migrations更新数据库结构(Code First )

    原文地址:http://blog.csdn.net/luoyeyu1989/article/details/8275237 背景 code first起初当修改model后,要持久化至数据库中时,总要 ...

  4. IOS UIVIEW layer动画 总结(转)

    转发自:http://www.aichengxu.com/article/%CF%B5%CD%B3%D3%C5%BB%AF/16306_12.html   IOS UIVIEW layer动画 总结, ...

  5. Java在mysql插入数据的时候的乱码问题解决

    今天在使用hibernate的时候,插入mysql的数据中的中文总是显示乱码,之前出现过类似的问题,但是没有太在意,今天又发生了.所以向彻底的解决一下. 参考的博文: http://www.cnblo ...

  6. 对jQuery.isArray方法的分析

    jQuery.isArray方法应于判断是不是数组,是的话返回true,否则返回false.调用如:jQuery.isArray([]),返回true.其实现源码如下: isArray: Array. ...

  7. 找出程序cpu使用率高的原因

    确定是CPU过高 使用top观察是否存在CPU使用率过高现象 找出线程 对CPU使用率过高的进程的所有线程进行排序 ps H -e -o pid,tid,pcpu,cmd --sort=pcpu |g ...

  8. cocos2d-x 多分辨率适配详解(转载),以前北京团队设计的游戏,也是用这套方案

    http://blog.csdn.net/kyo7552/article/details/17163487 多种分辨率的适配一直都是一个蛋疼的问题,各家公司可能都有自己的一套方案.今天我为大家介绍的是 ...

  9. 理解TCP/IP协议

    TCP/IP协议是Transmission Control Protocol/Internet Protocol的简写,中译名为传输控制协议/因特网互联协议. 单从TCP/IP协议这个名称看,好多人误 ...

  10. GCC警告选项例解

    程序员是追求完美的一族,即使是一般的程序员大多也都不想看到自己的程序中有甚至那么一点点的瑕疵.遇到任意一条编译器警告都坚决不放过.有人会说:我们可以使用比编译器更加严格的静态代码检查工具,如splin ...