首页 技术 正文
技术 2022年11月15日
0 收藏 358 点赞 4,461 浏览 1203 个字

题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1323

题意

长方形l * w,给出长方形中间那条线上n个圆的圆心c和半径r,选取最少数目的圆覆盖长方形,选不了输出-1

思路

明显,算出圆在边上的坐标,然后尽量从左向右扩展就行

感想:

卡题的原因是反射性以为r和w很小,但其实可以很大,所以用double存r

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<double, double> MyPair;
const int MAXN = 1e4 + ;
double c[MAXN];
double r[MAXN];
MyPair myRange[MAXN];
double posmx[MAXN];int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
int n, l, w;
for (int ti = ;cin>>n>>l>>w; ti++) {
for (int i = ; i < n; i++) {
cin >> c[i] >> r[i];
double gap = (r[i] >= (w / 2.0) ? sqrt(r[i] * r[i] - w * w / 4.0) : -);
myRange[i] = MyPair(c[i] - gap, c[i] + gap);
}
sort(myRange, myRange + n);
bool fl = myRange[].first <= ;
double pos = ;
int ans = ;
for (int i = ; i < n && fl && pos < l; ans++) {
double posNxt = -;
while (i < n && myRange[i].first <= pos) {
posNxt = max(posNxt, myRange[i].second);
i++;
}
if (posNxt <= pos && pos < l) { fl = false; }
else pos = posNxt;
}
if (!fl || pos < l)ans = -;
printf("%d\n", ans);
} return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,918
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,444
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,255
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,069
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,701
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,741