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 ...
随机推荐
- 6、tcp_wrapper
iptables的链接跟踪表最大容量为/proc/sys/net/ipv4/ip_conntrack_max,链接碰到各种状态的超时后就会从表中删除. 所以解決方法一般有两个: (1) 加大 ip_c ...
- 五、IO编程
input/output:输入.输出 Stream(流):Input Stream就是数据从外面(磁盘.网络)流进内存,Output Stream就是数据从内存流到外面去.(流:相当于管道) 由于CP ...
- mysql联合主键自增、主键最大长度小记
前言 一. 联合主键自增问题 今天上午闲来无事翻看了下数据库分类表的设计,看到这样一幕: 当时我好奇的是怎么cateId自增会存在重复值的问题,然后翻看了下主键是由siteId和cateId组成.所以 ...
- EDCheckPrefabRef
using UnityEngine;using System.Collections;using UnityEditor;using UnityEngine.UI;using System.Refle ...
- codeforces 15C. Industrial Nim
题目链接:http://codeforces.com/problemset/problem/15/C $NIM$游戏是次要的,直接异或石头堆就可以了,问题在于给出的石头堆的数量极多. 考虑利用异或的性 ...
- python 传递多个参数
def oper(a,*args): print(args) print(a) oper("q","s","d","z" ...
- python中常用的模块二
一.序列化 指:在我们存储数据的时候,需要对我们的对象进行处理,把对象处理成方便存储和传输的数据格式,这个就是序列化, 不同的序列化结果不同,但目的是一样的,都是为了存储和传输. 一,pickle.可 ...
- 负数字符串经过int处理之后还是负数
<?php $v = '-1'; $b = (int)$v; echo $b;
- Entity Framework框架 (一)
1. Entity Framework的详细介绍: Entity Framework简称EF,与Asp.net关系与Ado.net关系. Entity Framework是ado.net中的一组支持开 ...
- ie67的冷知识
1. _display:inline;是什么意思 只有ie6认识带下划线的,一般这种写法是用来消除ie6对margin双倍的bug的,比如你写margin-left:10px;那么ie6下显示的是20 ...