On the way to the park Gym - 101147I 几何
http://codeforces.com/gym/101147/problem/I
5 seconds
64 megabytes
walk.in
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?
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.
For each test case print one integer. The maximum number that could be displayed on the screen.
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
3
1
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 几何的更多相关文章
- Codeforces Gym 100803F There is No Alternative 暴力Kruskal
There is No Alternative 题目连接: http://codeforces.com/gym/100803/attachments Description ICPC (Isles o ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- hdu4607 Park Visit(树的直径)
Park Visit Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
随机推荐
- 打造基于Ubuntu+XBMC的家庭媒体中心
作为一名高清爱好者,一直想配置一台HTPC放家里实现高清播放外加家庭服务器功能.Nvidia的Ion平台自然是高清平台的硬件首选,而家庭媒体中心的软件端则首先考虑开发的已经很成熟的开源利器 XBMC ...
- 使用ffmpeg添加logo
1 网上搜出的一些ffmpeg添加logo的命令都不成功,调查了官方手册后以下这种用法成功: ffmpeg -y -i input.mp4 -vf "movie=logo.png [logo ...
- macbook清理磁盘空间
前言:作为一名程序员,使用MacBook时间久了之后难免都会遇到“磁盘空间不足”的警告,这时就可以清理如下文件夹,一般就可以清理出几十个G的大小! 1.删除“~/资源库/Developer/Xcode ...
- Idea中的插件-列出Java Bean的所有set方法
插件的git 地址: https://github.com/yoke233/genSets 将插件jar导入idea中,使用方式是对象后加.allset,然后回车.
- WPF-悬浮在底部的导航
先用Rectangle代替导航按钮,这个导航会悬浮在界面的底部,当鼠标移进导航按钮上的时候,按钮会放大,移出后恢复正常. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...
- Web app root system property already set to different value: 'webapp.root'
java.lang.IllegalStateException: Web app root system property already set to different value: 'webap ...
- ORA-12547: TNS:lost contact
碰到这个ORA-12547: TNS:lost contact的问题,翻了很多资料和METALINK,总结了一下原因: 1 是由于rpm包没有安装,对于我们的生产环境,此包是安装的. admin@p1 ...
- jquery的跨域请求
项目中关于ajax jsonp的使用,出现了问题:可以成功获得请求结果,但没有执行success方法总算搞定了,记录一下 function TestAjax() { $.ajax({ ...
- C++之const类成员变量,const成员函数
const修饰类的成员函数 const修饰变量一般有两种方式:const T *a,或者 T const *a,这两者都是一样的,主要看const位于*的左边还是右边,这里不再赘述,主要来看一下当co ...
- SQL Server中误删除数据的恢复
SQL Server中误删除数据的恢复本来不是件难事,从事务日志恢复即可.但是,这个恢复需要有两个前提条件: 1. 至少有一个误删除之前的数据库完全备份. 2. 数据库的恢复模式(Recovery m ...