首页 > 其他分享 >On the way to the park Gym - 101147I 几何

On the way to the park Gym - 101147I 几何

时间:2022-10-20 11:34:54浏览次数:75  
标签:area res Gym park 101147I Asem double include LL

​http://codeforces.com/gym/101147/problem/I​

I. On the way to the park

time limit per test

memory limit per test

input

output

Engineers around the world share a lot of common characteristics. For example, they're all smart, cool and extremely lazy!

Asem is a computer engineer, so he is very lazy. He doesn't leave the house for weeks. Not even for a shisha with his best friends.

One day his mother insisted that he goes to the park to get some fresh air. Asem is a lazy but a very practical person. He decided to use the time spent on the way to the park to test his new device for detecting wireless networks in the city. The device is as much advanced as it's weird. It detects a network if the coverage area of the network is entirely inside the coverage area of the device. Both the coverage area of the wireless networks and Asem's device are circular shaped.

The path between Asem's house and the park is a straight line and when Asem turn on the device, it display one integer on its screen, the sum of the radiuses of the detected networks.

Given the coordinates of the center of the networks coverage area and their radiuses, what is the maximum number that could be displayed on the screen knowing that Asem can test the device anywhere in the street?

Input

The first line of the input will contain T the number of test cases.

Each test case starts with two integers on a single line (0 < N ≤ 105), the number of wireless networks, (0 < M ≤ 109), the radius of the coverage area of Asem's device.

Then N lines follow, each describes a wireless network and contains three integers ( - 109 ≤ xi ≤ 109), the X coordinate of the center of the i'th network coverage area,( - 109 ≤ y ≤ 109), the Y coordinate of the center of the i'th network coverage area, (1 ≤ ri ≤ 109), the radius of the i'th network coverage area. Where the street is the X-axis here and Asem can test the device anywhere on it.

Output

For each test case print one integer. The maximum number that could be displayed on the screen.

Example

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

Output

3
1

Note

Large I/O files. Please consider using fast input/output methods.

The figure shows a possible solution for the first sample.

On the way to the park Gym - 101147I   几何_ios

 

对于每一个圆。可以算出一个区间[L, R]使得半径为m的圆在这个区间里,一定能包含它。

On the way to the park Gym - 101147I   几何_#include_02

 

然后就是区间减法问题里。用map存一下就好

On the way to the park Gym - 101147I   几何_ios_03

On the way to the park Gym - 101147I   几何_ios_04

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
int n, m;
const double eps = 1e-10;
bool flag;
double calcLeft(LL x, LL y, LL r) {
double t = m - r;
double res = t * t - y * y;
if (res < 0) {
flag = false;
return eps;
}
return x - sqrt(res);
}
double calcRight(LL x, LL y, LL r) {
double t = m - r;
double res = t * t - y * y;
// assert(res >= 0);
return x + sqrt(res);
}
map<double, LL>mp;
void work() {
mp.clear();
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
int x, y, r;
scanf("%d%d%d", &x, &y, &r);
if (r > m) continue;
flag = true;
double res = calcLeft(x, y, r);
if (flag) {
mp[res] += r;
mp[calcRight(x, y, r) + eps] -= r;
}
}
if (mp.size() == 0) {
printf("0\n");
return;
}
map<double, LL> :: iterator it1 = mp.begin();
LL ans = it1->second;
LL pre = it1->second;
it1++;
for (it1; it1 != mp.end(); it1++) {
pre += it1->second;
ans = max(ans, pre);
}
printf("%I64d\n", ans);
}

int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
freopen("walk.in", "r", stdin);
int t;
scanf("%d", &t);
while (t--) work();
return 0;
}

View Code

 

标签:area,res,Gym,park,101147I,Asem,double,include,LL
From: https://blog.51cto.com/u_15833059/5779589

相关文章

  • Rasheda And The Zeriba Gym - 100283A  计算几何
    ​​http://codeforces.com/gym/100283/problem/A​​考虑到多边形是不稳定的,是可以变来变去的。那么总是可以把每个点放到圆上。所以只需要判断圆心角是不是小于等于360即......
  • SparkCore(二)
    RDD的API操作/方法/算子比如有一个100M的csv文件,需要对它的每个元素操作,比如先+1,再平方,结果保存另一个csv文件。如下图,如果用传统python思维,不仅每个中间容器占用内存,消......
  • spark_base
    spark集群版原理Spark和其他大数据框架一样,计算都需要使用资源(【core】+【内存】#core就是cpu中的几核几线程的线程数1、如果只有一台服务器,那么就是使用【1台机器】的......
  • Livy,基于Apache Spark的开源REST服务,加入Cloudera Labs
    温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。Fayson的github:https://github.com/fayson/cdhproject提示:代码块部分可以左右滑动查看噢ClouderaLabs的新成......
  • SparkSQL参数
    SparkSQL参数<1>表分区类参数--是否允许动态生成分区sethive.exec.dynamic.partition=true;--是否容忍指定分区全部动态生成sethive.exec.dynamic.partition.mode=......
  • SparkSQL on K8s 在网易传媒的落地实践
    随着云原生技术的发展和成熟,大数据基础设施积极拥抱云原生是业内发展的一大趋势。网易传媒在2021年成功将SparkSQL部署到了K8s集群,并实现与部分在线业务的混合部署,......
  • Spark常规性能调优(一)
    1、常规性能调优一:最优资源配置Spark性能调优的第一步,就是为任务分配更多的资源,在一定范围内,增加资源的分配与性能的提升是成正比的 ,实现了最优的资源配置后,在此基础上再考......
  • spark通过pipline方式批量插入redis集群方式
    spark通过pipline方式批量插入redis集群网上资料比较少,但是有一大堆都是单机的方式,spring倒是也有写入redis集群的实现代码,以下整理了spark通过pipline批量写入的方式,速度......
  • Exam Results Gym - 102769E
    https://vjudge.net/problem/Gym-102769E#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>usingnamespacestd;typedeflonglongll;......
  • 【云原生】Spark on k8s 讲解与实战操作
    目录一、概述二、开始Sparkonk8s运行原理三、Spark运行模式1)cluster模式2)client模式四、开始Sparkonk8s编排1)下载Spark包2)构建镜像3)配置spark用户权限4)提交Sp......