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 ...
随机推荐
- vue.js精讲02
2017-09-17 笔记及源码地址 : https://github.com/wll8/vue_note vue 中的事件深入. 事件: @click/mouseover…事件简写: @ 如 @cl ...
- HDU 5844 LCM Walk(数学逆推)
http://acm.hdu.edu.cn/showproblem.php?pid=5584 题意: 现在有坐标(x,y),设它们的最小公倍数为k,接下来可以移动到(x+k,y)或者(x,y+k).现 ...
- shp与json互转(转载)
转自:http://blog.sina.com.cn/s/blog_673c98be0102v78i.html 对于搞GIS开发的,这2种数据格式太重要了. 一.shp转json 这个要容易些,方法也 ...
- RN中关于IOS和Android的相关权限的问题
在日常的开发中,时常需要去获取应用的一权限 比如查看通讯录/打开摄像机等 1:ios iOS 的权限管理在info.plist里设置 info.plist主要是管理了app 的一些信息文件,比如版本 ...
- 基于 Python 和 Pandas 的数据分析(1)
基于 Python 和 Pandas 的数据分析(1) Pandas 是 Python 的一个模块(module), 我们将用 Python 完成接下来的数据分析的学习. Pandas 模块是一个高性 ...
- python的json模块的dumps,loads,dump,load方法介绍
dumps和loads方法都在内存中转换, dump和load的方法会多一个步骤,dump是把序列化后的字符串写到一个文件中,而load是从一个文件中读取字符串 将列表转为字符串 >>&g ...
- python字符串用法
一,数据类型的转换 1常用的数据类型有int,str,bool三种; int是整型:一般的操作是查找数据的二进制长度bit_length() 一般数据有: 1)二进制:逢二进一 2)十进制,(0-9) ...
- DAY4 if、while和for
一.if 判断 语法一: if 条件: # 以下是上一条if 的子代码块 print(子代码1) print(子代码2) print(子代码3) if 运行完之后会执行代码下方 上一缩进级 的代码块 ...
- ubuntu配置chrome git
安装chrome (也可以直接从官网下载deb包安装) sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/ ...
- linux修改网卡名为eth0
方法1: 1.编辑网卡的配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ens33 将里面的NAME和DEVICE项修改为eth0,ONBOOT修改为yes. ...