bzoj [Usaco2009 Hol]Cattle Bruisers 杀手游戏

news/2025/2/24 16:25:32

Description

 

 

Input

 第1行输入N,R,BX,BY, BVX,BVY,之后N行每行输入四个整数Xi,Yi,VXi,VYi.

 

Output

 

    一个整数,表示在逃脱过程中,某一个时刻最多有这个数理的杀手可以射杀贝茜.

Sample Input

3 1 0 0 0 2
0 -3 0 4
1 2 -1 1
1 -2 2 -1

Sample Output

2

OUTPUT DETAILS:

At time 1.5, Bessie is at point (0, 3), and the three bruisers are
at points (0, 3), (-0.5, 3.5), and (4, -3.5). The first two cattle
bruisers are within 1 unit of Bessie, while the third will never
be within 1 unit of Bessie, so 2 is the most achievable.
 
思路:  我们可以计算出每个杀手可以射击的一个时间范围,然后做扫描线。时间复杂度$O(nlogn)$
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int const N = 50000 + 3;
 4 double const eps = 1e-8;
 5 int n, r, m, in[N], out[N], cnt;
 6 double bx, by, bvx, bvy, x[N], y[N], vx[N], vy[N], t1[N], t2[N], t[N << 2];
 7 void calc(int k) {
 8     double tx = x[k] - bx;
 9     double ty = y[k] - by;
10     double v1 = vx[k] - bvx;
11     double v2 = vy[k] - bvy;
12     double a = v1 * v1 + v2 * v2;
13     double b = 2 * v1 * tx + 2 * v2 * ty;
14     double c = tx * tx + ty * ty - 1.0*r * r;
15     double d = b * b - 4 * a * c;
16     if(fabs(a) < eps ) {
17         if( c<0) { // 这个我始终觉得很奇怪,为什么c小于0就无限解了。
18             m++;
19             t1[m] = 0;
20             t2[m] = 1e10;
21         }
22         return ;
23     }
24     if(d<0) return ;
25     t1[k] = (-b - sqrt(d)) / (2 * a);
26     t2[k] = (-b + sqrt(d)) / (2 * a);
27     if(t2[k] <0)
28         return ;
29     t1[k] = max(0.0, t1[k]);
30     m++;
31     t1[m] = t1[k];
32     t2[m] = t2[k];
33 }
34 int main() {
35     scanf("%d%d%lf%lf%lf%lf", &n, &r, &bx, &by, &bvx, &bvy);
36     for(int i = 1; i <= n; i++) {
37         scanf("%lf%lf%lf%lf", &x[i], &y[i], &vx[i], &vy[i]);
38         calc(i);
39     }
40     for(int i = 1; i <= m; i++) {
41         ++cnt;
42         t[cnt] = t1[i];
43         ++cnt;
44         t[cnt] = t2[i];
45     }
46     sort(t + 1, t + cnt + 1);
47     int c = unique(t, t + cnt + 1) - t - 1;
48     for(int i = 1; i <= m; i++) {
49         int a = lower_bound(t + 1, t + c + 1, t1[i]) - t;
50         int b = lower_bound(t + 1, t + c + 1, t2[i]) - t;
51         in[a]++;
52         out[b]++;
53     }
54     int ans = 0, now = 0;
55     for(int i = 1; i <= c; i++) {
56         now += in[i];
57         ans = max(ans, now);
58         now -= out[i];
59     }
60     printf("%d\n", ans);
61     return 0;
62 }
View Code

 

转载于:https://www.cnblogs.com/ZJXXCN/p/10771266.html


http://www.niftyadmin.cn/n/712829.html

相关文章

乐玩自动化测试模块_Python自动化测试——必会模块 Unittest

前言&#xff1a;一直在努力做测试的小白白 个人觉得使用python标准库中的Unittest搭建自动化测试框架很好用所以在这里做个笔记。Unittest模块核心概念非为四层先后顺序可以为TestFixture->TestCase->TestSuite->TestRunner Surprise MotherF*cker 跟这个图有什么关系…

DES加密解密

自己写的DES加密解密类&#xff0c;加密后生成Base64字符串&#xff0c;并去除字符。 加密后替换掉&#xff0c;这样加密后的字符串可以作为url参数传递。 using System; using System.IO; using System.Security.Cryptography; using System.Text;namespace QuaEdu.Helper {//…

bootstrap下拉选择框选中事件_基于jQuery的select下拉框选择触发事件实例分析

本文实例讲述了基于jQuery的select下拉框选择触发事件实现方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;我一直以来都认为&#xff0c;select 下拉框选择对选项 options 使用 onclick 注册事件即可&#xff0c;如下&#xff1a;选项一选项二今天有个要求需要做联…

麒麟开源堡垒主机在等保上的合规性分析

信息安全等级保护工作包括定级、备案、安全建设和整改、信息安全等级测评、信息安全检查五个阶段。 我国的信息安全等级保护共分为五级&#xff0c;级别越高&#xff0c;要求越严格。 我国的信息安全等级保护主要标准包括&#xff0c;《信息系统等级保护安全设计技术要求&…

CodeForces 6A-Triangle(枚举/暴力)

题目描述&#xff1a; Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of fo…

纠结的一天 —— 由base64编解码与加号、空格引起

2014年3月14日&#xff0c;星期五&#xff0c; 23点22分 忙碌、焦头烂额、充实而又幸福的一天&#xff01; 写在篇头的话&#xff1a; 许多时候&#xff0c;别人分享的经验&#xff08;成功或失败&#xff09;&#xff0c;个中滋味&#xff0c;听者很难真正体会&#xff0c;直到…

pycharm运行Django项目,提示UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6

确认pycharm编码都是utf-8的情况下&#xff0c;需要修改项目中settings.py DIRS: [ ],默认是空&#xff0c;将路径加入即可解决。 TEMPLATES [{BACKEND: django.template.backends.django.DjangoTemplates,DIRS: [os.path.join(BASE_DIR, templates)],APP_DIRS: True,OPTIONS…

机器学习实战 笔记文章链接

声明 《机器学习实战》读书笔记系列是我对在读此书过程中遇到的各种问题、及解决方法的记录和总结。 另外我修改了部分源代码&#xff0c;并添加了注释&#xff0c;希望能够帮助到大家。 文章列表 《机器学习实战》读书笔记1&#xff1a;NumPy的安装及简单用法 《机器学习实…