LOJ #10002. 喷水装置
2024-10-08 15:00:02
裸的贪心。
基本思想见图:
Code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 15001;
int T;
int cnt,n,L,W;
int ans;
struct rou
{
int l;
int r;
}a[N];
bool cmp(rou x,rou y)
{
return x.l<y.l;
}
void work()
{
cnt=0;
ans=0;
//这是一个很日学的东西,卡了我一个星期。
//以后一看见“有多组数据”,就想到work函数内付0.
scanf("%d%d%d",&n,&L,&W);
for(int i=1;i<=n;++i)
{
int C,R;
scanf("%d%d",&C,&R);
if(2*R<=W)
continue;
a[++cnt].l=C-sqrt(R*R-W*W/4.0);
a[cnt].r=C+sqrt(R*R-W*W/4.0);
}
sort(a+1,a+cnt+1,cmp);
int t=0;
while(t<L)
{
++ans;
int s=t;
for(int i=1;i<=cnt;++i)
if(a[i].l<=s&&t<a[i].r)
t=a[i].r;
if(t==s&&t<L)
{
printf("-1\n");
return;
}
}
printf("%d\n",ans);
}
int main()
{
scanf("%d",&T);
for(int t=1;t<=T;++t)
work();
return 0;
}
血泪啊!
一定要吸取教训啊!!
啊!!!
最新文章
- web开发工具软件使用问题记录
- WIN7下使用VC2010调试uCOS-II 2.91
- Hadoop组成
- 解决vsftpd日志时间问题
- UC编程之线程
- jquery获取表单的值
- SQL Server 的远程连接(转载)
- Course Schedule ——LeetCode
- 感兴趣的Linux发行版
- iOS开发之使用Ad Hoc进行测试
- 关于ASP.NET WebAPI中HTTP模型的相关思考
- Android studio出现Error:Unable to tunnel through proxy. Proxy returns ";HTTP/1.1 400 Bad Reques的解决办法
- 将Windows 8.1 系统窗口背景设置成淡绿色?
- vue项目如何通过前端实现自动识别并配置服务器环境地址
- 【BZOJ1818】[CQOI2010]内部白点(树状数组,扫描线)
- producter-consumer 他山之石
- 关于xftp上传文件状态错误的解决
- 深入探讨 Java 类加载器(转载)
- 调试一个Ext打开的window窗口内嵌Iframe的form提交问题
- jeesite介绍及链接