Guarding Bananas
Guarding Bananas
Once there was a lazy monkey in a forest. But he loved banana too much. One day there was a storm in the jungle and all the bananas fell from the trees. The monkey didn't want to lose any of the bananas. So, he wanted to find a banana such that he can eat that and he can also look after the other bananas. As he was lazy, he didn't want to move his eyes too wide. So, you have to help him finding the banana from where he can look after all the bananas but the degree of rotating his eyes is as small as possible. You can assume that the position of the bananas can be modeled as 2D points.
Here a banana is shown, from where the monkey can look after all the bananas with minimum eye rotation.
Input
Input starts with an integer T (≤ 13), denoting the number of test cases.
Each case starts with a line containing an integer n (1 ≤ n ≤ 105) denoting the number of bananas. Each of the next n lines contains two integers x y (-109 ≤ x, y ≤ 109) denoting the co-ordinate of a banana. There can me more than one bananas in the same co-ordinate.
Output
For each case, print the case number and the minimum angle in degrees. Errors less than 10-6 will be ignored.
Sample Input
2
1
4 4
4
0 0
10 0
10 10
2 1
Sample Output
Case 1: 0
Case 2: 45.0000000
Hint
Dataset is huge. Use faster I/O methods.
没有什么好说的,求凸包面积,直接上模板.
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
;
const double PI=acos(-1.0);
;
:x<?-:;}
struct point{double x,y;}a[maxn],ch[maxn];
bool operator < (point x,point y){return x.x<y.x||x.x==y.x&&x.y<y.y;}
bool operator == (point x,point y){return x.x==y.x&&x.y==y.y;}
point operator - (point x,point y){point ret; ret.x=x.x-y.x,ret.y=x.y-y.y; return ret;}
double angle(point x){return atan2(x.y,x.x);}
double cross(point x,point y){return x.x*y.y-x.y*y.x;}
int Andrew(point *a, int n, point *ch){
sort(a,a+n);
;
; i<n; i++) {
&&dcmp(cross(ch[m-]-a[i],ch[m-]-a[i])) <= ) m--;
ch[m++]=a[i];
}
int k=m;
; i>=; i--) {
]-a[i],ch[m-]-a[i])) <= ) m--;
ch[m++]=a[i];
}
) m--;
return m;
}
int main(){
int T,n,ts;
; ts<=T; ts++){
scanf("%d",&n);
; i<n; i++) scanf("%lf%lf", &a[i].x,&a[i].y);
){printf("Case %d: 0.0000000\n",ts); continue;}
n=Andrew(a,n,ch);
; i<; i++) ch[i+n]=ch[i];
double mini=1e10;
; i<n; i++){
]);
]-ch[i+]);
double da=fabs(ang1-ang2);
if (da>PI) da=2.0*PI-da;
mini=min(mini,da*180.0/PI);
}
printf("Case %d: %.7f\n",ts,mini);
}
;
Guarding Bananas的更多相关文章
- LightOJ 1203 Guarding Bananas (凸包最小顶角)
题目链接:LightOJ 1203 Problem Description Once there was a lazy monkey in a forest. But he loved banana ...
- LightOj1203 - Guarding Bananas(凸包求多边形中的最小角)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1203 题意:给你一个点集,求凸包中最小的角:模板题,但是刚开始的时候模板带错了,错的我 ...
- LightOJ 1203--Guarding Bananas(二维凸包+内角计算)
1203 - Guarding Bananas PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 M ...
- Soldier and Bananas
Soldier and Bananas 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给 ...
- CodeForces 546A-Soldier and Bananas
题意: 有n dollar,the first banana cost k dollars,第i个就需cost k*i,问买w个bananas是否需要借钱:借钱需要多少? 分析:首先计算w个bana ...
- BZOJ 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
题目 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 491 S ...
- 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场
1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 498 Solve ...
- [Swift]LeetCode875. 爱吃香蕉的珂珂 | Koko Eating Bananas
Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i]bananas. The gu ...
- Koko Eating Bananas LT875
Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The g ...
随机推荐
- 4、keepalived高可用nginx负载均衡
keepalived: HTTP_GET //使用keepalived获取后端real server健康状态检测 SSL_GET(https) //这里以为这后端使用的是http协议 ...
- 【Selenium2】【Jenkins】
1. 下载Tomcat ,Windows7 环境,http://tomcat.apache.org/ 我下载的是版本8 2. 下载Jenkins,Windows7 环境,http://jenkins ...
- .Net MVC关于子页面引用js库问题
layout页面中的配置: @RenderSection("scripts", required: false) @RenderSection("Styles" ...
- JAVA读取CSV文件到MySQL数据库中
maven项目pom配置: <dependency> <groupId>net.sourceforge.javacsv</groupId> <artifact ...
- 在用node安装某个全局模块的时候,没有权限修改node_modules
一.问题 今天在安装公司内部的一个npm模块的时候,发现报错了⬇ 第一行错误: deprecated graceful-fs@1.2.3: please upgrade to graceful-fs ...
- 【三】php 数组
数组 1.数字索引数组:array('a','b','c'); 2.访问数组内容 $arr[下标] 3.新增数组元素 $arr[下标]=内容 4.使用循环访问数组 //针对数字索引 $arr=arr ...
- Mysql 查看定时器 打开定时器 设置定时器时间
1.查看是否开启evevt与开启evevt. 1.1.MySQL evevt功能默认是关闭的,可以使用下面的语句来看evevt的状态,如果是OFF或者0,表示是关闭的. show VARIABLES ...
- Ubuntu ls: cannot open directory .: Permission denied
把该目录赋予权限: sudo chmod xxx
- 鼠标经过事件(onmouseover)
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- Java 层序创建和遍历二叉树
直接上代码 package te.com; import java.util.LinkedList; import java.util.Queue; import java.util.logging. ...