USACO: Fencing the Cows

Fencing the Cows
Hal Burch

Farmer John wishes to build a fence to contain his cows, but he's a bit short on cash right. Any fence he builds must contain all of the favorite grazing spots for his cows. Given the location of these spots, determine the length of the shortest fence which encloses them.

PROGRAM NAME: fc

INPUT FORMAT

The first line of the input file contains one integer, N. N (0 <= N <= 10,000) is the number of grazing spots that Farmer john wishes to enclose. The next N line consists of two real numbers, Xi and Yi, corresponding to the location of the grazing spots in the plane (-1,000,000 <= Xi,Yi <= 1,000,000). The numbers will be in decimal format.

SAMPLE INPUT (file fc.in)

4
4 8
4 12
5 9.3
7 8

OUTPUT FORMAT

The output should consists of one real number, the length of fence required. The output should be accurate to two decimal places.

SAMPLE OUTPUT (file fc.out)

12.00


最水的凸包啦,分析:由三角不等式可推出,使用凸包来包围所有的点,周长最小

刚好算法分析的课本上讲了个分治解凸包的算法,于是决定试一试,结果tmd各种纠结(特别是在合并两个凸包的时候),真是百思不得其解为神马复杂度同为O(nlogn),却硬要这样解呢?

最后还是用回直接扫描,本来以为还要考虑精度问题,先试试提交再说,结果就过了,orz。。。

 

PS:要考虑一种特殊的情况我也没写进去:假设a、b、c三点的极坐标角相同,那些对它们进行排序的时候就应该按距离r升序或者降序排列。不过这道题的数据确实很难做到这一点——因为每个人选择观察者位置的时候都可能会有自己特殊的想法,所以这个漏洞就不怪USACO啦~

 

代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值