UVA 11928 The Busy Dog
题意:一只狗被拴在杆子上,从起点开始按直线依次跑到给出的点最后回到起点问绕杆子几圈,逆时针为正,顺时针为负,撞到杆子输出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的更多相关文章
- UVa 二分图匹配 Biginners
UVa 1045 - The Great Wall Game 最小权匹配 题意:给你一个n*n的棋盘,上面有n个棋子,要求通过移动各个棋子使得棋子在同一行或者同一列或者对角线上,求最小移动次数. 思路 ...
- 二分图最大匹配(匈牙利算法) UVA 670 The dog task
题目传送门 /* 题意:bob按照指定顺序行走,他的狗可以在他到达下一个点之前到一个景点并及时返回,问狗最多能走多少个景点 匈牙利算法:按照狗能否顺利到一个景点分为两个集合,套个模板 */ #incl ...
- ●UVA 11796 Dog Distance
题链: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11796 Dog Distance(几何)
Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...
- UVA 11796 - Dog Distance 向量的应用
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 简单几何(相对运动距离最值) UVA 11796 Dog Distance
题目传送门 题意:两只狗在折线上跑,速度未知,同时出发,同时达到.问跑的过程中,两狗的最大距离和最小距离的差 分析:训练指南P261,考虑相对运动,设A静止不动,B相对A运动,相对的运动向量:Vb - ...
- UVA 11796 - Dog Distance
题意 两条狗啊,同时跑,,同时结束,各自跑各自的道路,问跑的过程中,他们最大距离和最小距离的差: 方法 恶心一点就是,最大最小距离的求解方法,假设两只狗都只有一条线段要跑,则可以判定在端点处有最大 ...
- UVA 11796 Dog Distance(向量)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...
- 转: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? ...
随机推荐
- 2016 系统设计第一期 (档案一)MVC ajax 获取json数据
我在做一张表的增删改查的时候,在编辑的时候,需要获取当前选择行对应的Id,然后并且把选择行的Id的对于的数据取出来,代码如下: 列表a标签绑定: Js代码: url: '/Users/GetUserB ...
- MVC5+EF6+BootStrap3.3.5 博客系统之EF(一)
- Mac 启用http-dav功能(WebDAV服务器)
启用Mac的WebDAV可以实现文件的上传以及Windows.Linux和Mac之间的数据互传. 客户端使用:windows下使用网上邻居 --> 添加一个网上邻居 --> 输入uplo ...
- 3.8 spring - AbstractBeanDefinition 介绍
之前,我们已尽完成了xml 文档到 GenericBeanDefinition的转换, 也就是说,到这里,所有的配置都可以在GenericBeanDefinition 的实例中找到对应的配置. Gen ...
- 解决VS如何同时打开两个工程(xp和win7)
http://www.360doc.com/content/11/1020/00/7891073_157586269.shtml
- [转载]Unity3D的断点调试功能
断点调试功能可谓是程序员必备的功能了.Unity3D支持编写js和c#脚本,但很多人可能不知道,其实Unity3D也能对程序进行断点调试的.不过这个断点调试功能只限于使用Unity3D自带的MonoD ...
- TIANKENG’s restaurant
Problem B:http://codeforces.com/contest/616/problem/B B. Dinner with Emma 题意:一对夫妻要去餐厅吃晚饭,Emma 想去最豪华( ...
- spoj 338
题意: 无向图 每条边有长度和费用两个属性 求从点1到点n 在花费不超过 k 的情况下的最短路径 BFS 使用优先队列 长度短的优先出列 题解上的方法没看懂 不知道怎么用链表维护 . ...
- About javascript closure
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Closures?redirectlocale=en-US&redi ...
- Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...