GYM 101147 I.On the way to the park(水~)
来源:互联网 发布:华为海洋网络 面试 编辑:程序博客网 时间:2024/05/21 23:03
Description
给出一些小圆的圆心和半径,问一个圆心在x轴上,半径为R的大圆最多可以包含多少小圆
Input
第一行一整数T表示用例组数,每组用例首先输入两个整数n和R分别表示小圆数量和大圆半径,之后n行每行三个整数x,y,r表示一个小圆的圆心和半径(1<=n<=1e5,1<=R,r<=1e9,-1e9<=x,y<=1e9)
Output
输出大圆最多可以包含多少个小圆
Sample Input
2
3 5
0 0 1
4 0 2
10 0 1
4 3
0 1 1
0 -3 1
10 1 1
0 -4 2
Sample Output
3
1
Solution
求出每个小圆被包含需要的大圆半径横坐标取值范围,那么问题变成给出n个区间,问一个点最多能被多少区间覆盖,前缀和即可
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 111111typedef pair<double,int>P;P p[2*maxn];int T,n,R;int main(){ freopen("walk.in","r",stdin); scanf("%d",&T); while(T--) { scanf("%d%d",&n,&R); int res=0; while(n--) { int x,y,r; scanf("%d%d%d",&x,&y,&r); if(r>R||abs(y)>R-r)continue; double temp=sqrt(1.0*(R-r)*(R-r)-1.0*y*y); p[res++]=P(1.0*x-temp,-r),p[res++]=P(1.0*x+temp,r); } sort(p,p+res); ll ans=0,sum=0; for(int i=0;i<res;i++) sum+=p[i].second,ans=max(ans,-sum); printf("%I64d\n",ans); } return 0;}
0 0
- GYM 101147 I.On the way to the park(水~)
- I‘m on the way
- I am on the way to be a software engineer
- on the way to c++
- Hello,Dream!I am On The Way!
- Yiwu Exhibition industry:on the way to the world
- clearcase on the way!
- Notes on the Way
- On the way
- on the way
- On the way
- on the way
- On the way
- On the way
- JAVA on the way
- 论文!on the way!
- On the way
- 学习。On the way 。
- Android studio sdk tools 下缺失下载选项问题
- Android权限管理PermissionsDispatcher2.3.2使用+原生6.0权限使用
- 利用jquery实现select下拉框级联效果
- 开放-封闭原则(OCP)
- yii2中restful url访问配置, 登陆接口access-token验证类
- GYM 101147 I.On the way to the park(水~)
- yii2中restful url访问配置, 登陆接口access-token验证类
- 反射结合工厂设计模式的使用
- 常见的移动端H5页面开发遇到的坑和解决办法
- 蓝桥杯(历届真题)——连号区间数
- 阶乘之和
- 机智云程序原码分析
- gulp学习之四------压缩 CSS
- Python赋值、浅拷贝与深拷贝之间的区别