Codeforces Round #276 (Div. 2) B. Valuable Resources 二分
来源:互联网 发布:mysql官网怎么下载 编辑:程序博客网 时间:2024/06/08 08:52
由于边界与坐标轴平行,则只需确定正方形的左下角和边长即可确定正方形。
而左下角可以根据mines的坐标确定,所以只需二分枚举正方形的边长即可,给定边长,O(n)时间内可以检查是否满足。
代码如下:
#include <cstdio>#define N 1005#define INF 1000000001int x[N], y[N], n, orig_x = INF, orig_y = INF;bool check(int len){int right = orig_x + len, up = orig_y + len;for(int i = 0; i < n; i ++){if(!(x[i] >= orig_x && x[i] <= right && y[i] >= orig_y && y[i] <= up))return false;}return true;}int main(){scanf("%d", &n);for(int i = 0; i < n; i ++){scanf("%d %d", &x[i], &y[i]);if(x[i] < orig_x)orig_x = x[i];if(y[i] < orig_y)orig_y = y[i];}int l = 0, r = 2 * INF;while(l < r){int mid = l + ((r - l) >> 1);if(check(mid))r = mid;elsel = mid + 1;}printf("%I64d\n", (long long)l * l);return 0;}
0 0
- Codeforces Round #276 (Div. 2) B. Valuable Resources 二分
- 【Codeforces Round 276 (Div 2)B】【水题】Valuable Resources 最小正方形包含所有点
- 【CODEFORCES】 B. Valuable Resources
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces 485B Valuable Resources(水题)
- Codeforces Round #176 (Div. 2) B. Pipeline//二分查找
- Codeforces Round #271 (Div. 2) --B Worms (二分)
- Codeforces Round #311 (Div. 2) B. Pasha and Tea【二分】
- Codeforces Round #367 (Div. 2) B Interesting drink【二分】
- 【Codeforces Round 367 (Div 2) B】【二分查找】Interesting drink
- Codeforces Round #367 (Div. 2) B Interesting drink(二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- Codeforces Round #377 (Div. 2)A,B,C,D【二分】
- Codeforces Round #367 (Div. 2) B. Interesting drink(二分)
- Codeforces Round #403 Div. 2 A B 二分
- Codeforces Round #277.5(Div. 2) B. BerSU Ball【二分匹配】
- Codeforces Round #403 (Div. 2) B 二分 or 三分
- 修改InitPHP的分页类 使用BootStrap
- 对Windows10虚拟桌面的简单研究
- 【Hibernate四】关系映射之一对多双向关联
- 常用软件通讯端口
- 使用ContentObserver监听数据库变化
- Codeforces Round #276 (Div. 2) B. Valuable Resources 二分
- Adaptive Compressive Tracking via Online Vector Boosting Feature Selection(ACT算法解读)
- 2006_Assassins
- 负载均衡的算法
- Google's Python Class(二)——Python 字符串
- SharedPreferences详解1
- 用实例给新手讲解RSA加密算法
- 面试题4:哈希表
- JavaScript Function类型