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

I. On the way to the park
time limit per test

5 seconds

memory limit per test

64 megabytes

input

walk.in

output

standard 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.

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

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

#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-;
bool flag;
double calcLeft(LL x, LL y, LL r) {
double t = m - r;
double res = t * t - y * y;
if (res < ) {
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 = ; 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() == ) {
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 ;
}

On the way to the park Gym - 101147I 几何的更多相关文章

  1. Codeforces Gym 100803F There is No Alternative 暴力Kruskal

    There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...

  2. Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...

  3. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  4. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  7. hdu4607 Park Visit(树的直径)

    Park Visit Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  9. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

随机推荐

  1. Js中获取显示器、浏览器以及窗口等的宽度与高度的方法

    网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...

  2. 程序移植到VS2010,编译成功但是无法启动lib文件

    今天遇到的这个问题,是由于解决方案下有多个项目,其中包含生成库的项目,也有可执行程序的项目 解决方法:邮件解决方案,属性-通用属性-启动项目进行设置就OK了,我的是设置单启动项目为包含可执行程序的项目 ...

  3. FLV文件格式解析(转)

    FLV(Flash Video)是现在非常流行的流媒体格式,由于其视频文件体积轻巧.封装播放简单等特点,使其很适合在网络上进行应用,目前主流的视频网站无一例外地使用了FLV格式.另外由于当前浏览器与F ...

  4. Rsyslog 日志相关内容

    [root@server vusers_home]# rpm -ql rsyslog|more       ###.so结尾为模块,模块有分im为输入模块,om 为输出模块/etc/logrotate ...

  5. 光流 LK 金字塔

    文章转载自:https://blog.csdn.net/sgfmby1994/article/details/68489944 光流是图像亮度的运动信息描述,这种运动模式指的是由一个观察者(比如摄像头 ...

  6. poj1151 Atlantis——扫描线+线段树

    题目:http://poj.org/problem?id=1151 经典的扫描线问题: 可以用线段树的每个点代表横向被矩形上下边分割开的每一格,这样将一个矩形的出现或消失化为线段树上的单点修改: 每个 ...

  7. Winform安装包出现无法访问网络位置

    1.原因:安装包的安装路径出现了问题 2.如下图:错误路径 3.如下图:正确路径

  8. windows install JDK&&JRE

    重装系统后,安装的java环境没了,只能重装一下~~~~ 1.下载JDK 2.这里会安装两次,其中第一次为安装 JDK,第二次安装JRE,建议不要将这两个放在同一个文件夹. 3.配置环境变量 用鼠标右 ...

  9. PHP错题误区

    1,$bool = TRUE;echo gettype($bool);  //这个输出类型:booleanecho is_string($bool);  //这个用echo是不能输出布尔型的,只有va ...

  10. EF Core的安装、EF Core与数据库结合

    一.新建一个.net core的MVC项目                         新建好项目后,不能像以前一样直接在新建项中添加ef, 需要用命令在添加ef的依赖      二.EF Cor ...