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? ...
随机推荐
- .net google calendar
https://developers.google.com/gdata/client-cs http://www.codeproject.com/Articles/64474/How-to-Read- ...
- Python之print语句
print语句可以向屏幕上输出指定的文字.比如输出'hello, world',用代码实现如下: >>> print 'hello, world' 注意: 1.当我们在Python交 ...
- 慎用ReentrantLock
前言: 代码简洁与性能高效无法两全其美,本文章专注于并发程序的性能,如果您追求代码简洁,本文章可能不太适合,本文章属于Java Concurrency in Practice读书笔记. 在java5中 ...
- 关于C语言的输入-scanf、gets、getchar、getch、getline
找工作刷题,重拾C语言,发现对键盘输入掌握很生疏,现总结各类输入函数使用方法和注意事项如下. 1.scanf("格式说明",变量地址列表) scanf("%s" ...
- org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.chen.vo.Dept.parentId
异常描述:执行以下的addAsHaveParentId2方法出现此异常: /*-----------------------类Dept.Dept.hbm.xml有parentId属性(数据库中有此列) ...
- BZOJ 1706: [usaco2007 Nov]relays 奶牛接力跑
Description FJ的N(2 <= N <= 1,000,000)头奶牛选择了接力跑作为她们的日常锻炼项目.至于进行接力跑的地点 自然是在牧场中现有的T(2 <= T < ...
- uva 437 hdu 1069
dp 将石块按三个面存入队列 按底面积排序 dp就最大高度 按嵌套矩形最长路做做法 #include <iostream> #include <cstdio> #inc ...
- CF 369 B. Valera and Contest
http://codeforces.com/contest/369/problem/B 题意 :n, k, l, r, sall, sk,n代表的是n个人,这n个人的总分是sall,每个人的得分大于 ...
- What is the innovator’s solution——什么才是创新的解决方案2
前略:http://www.cnblogs.com/Kassadin/p/4233497.html 案例1 从书上的一个案例开始: 让我们来看看AT&T公司(美国电话电报公司)的案例吧.198 ...
- 玩转redis
http://www.cnblogs.com/huangxincheng/p/5002794.html