Shooting Game FZU - 2144 区间覆盖贪心

别再手动切换了!用SP3485+三极管搞定RS485自动收发电路(附完整原理图) 本文详细介绍了如何利用SP3485芯片和三极管设计RS485自动收发电路,解决传统手动切换带来的IO资源占用和软件复杂度问题。通过原理分析、电路设计拆解和实战注意事项,帮助工程师打造稳定可靠的自动收发通信模块,显著提升系统性能和可靠性。 阅读详情

Shooting Game

FZU - 2144

Fat brother and Maze are playing a kind of special (hentai) game in the playground. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.) But as they don’t like using repellent while playing this kind of special (hentai) game, they really suffer a lot from the mosquito. So they decide to use antiaircraft gun to shoot the mosquito. You can assume that the playground is a kind of three-dimensional space and there are N mosquitoes in the playground. Each of them is a kind of point in the space which is doing the uniform linear motion. (匀速直线运动) Fat brother is standing at (0, 0, 0) and once he shoot, the mosquito who’s distance from Fat brother is no large than R will be shot down. You can assume that the area which Fat brother shoot is a kind of a sphere with radio R and the mosquito inside this sphere will be shot down. As Fat brother hate these mosquito very much, he wants to shoot as much mosquito as he can. But as we all know, it’s tired for a man to shoot even if he is really enjoying this. So in addition to that, Fat brother wants to shoot as less time as he can.

You can (have to) assume that Fat brother is strong enough and he don’t need to rest after shooting which means that can shoot at ANY TIME.


Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case starts with two integers N and R which describe above.

Then N lines follow, the ith line contains six integers ax, ay, az, dx, dy, dz. It means that at time 0, the ith mosquito is at (ax, ay, az) and it’s moving direction is (dx, dy, dz) which means that after time t this mosquito will be at (ax+dx*t, ay+dy*t, ax+dz*t). You can assume that dx*dx + dy*dy+ dz*dz > 0.

1 <= T <= 50, 1 <= N <= 100000, 1 <= R <= 1000000

-1000000 <= ax, ay, az <= 1000000

-100 <= dx, dy, dz <= 100

The range of each coordinate is [-10086, 10086]

Output

For each case, output the case number first, then output two numbers A and B.

A is the number of mosquito Fat brother can shoot down.

B is the number of times Fat brother need to shoot.

Sample Input
6
2 1
2 0 0 -1 0 0
-2 0 0 1 0 0
2 1
4 0 0 -1 0 0
-2 0 0 1 0 0
2 1
4 0 0 -1 0 0
1 0 0 1 0 0
2 1
1 1 1 1 1 1
-1 -1 -1 -1 -1 -1
1 1
0 0 0 1 0 0
3 1
-1 0 0 1 0 0
-2 0 0 1 0 0
4 0 0 -1 0 0
Sample Output
Case 1: 2 1
Case 2: 2 1
Case 3: 2 2
Case 4: 0 0
Case 5: 1 1
Case 6: 3 2

题意:一个人在空间直角坐标系的原点,即是(0,0,0), 他的射程范围是以R为半径的球体,有n只蚊子,每只蚊子都会有原始坐标和三个坐标方向的速度,人要尽量把多的蚊子射下来,并且开枪次数最少。


思路:假设一只蚊子能进入这个球体,必然有一个进入时间和离开时间,我们设为t,蚊子当前坐标为x = ax + dx * t, y = ay + dy * t, z = az + dz * t, 通过两点距离公式可知

(x - 0)^2 + (y - 0)^2 + (z - 0)^2  <= r,把r移到不等式左边,xyz代入进行化简,就是一条一元二次不等式

(dx^2 + dy^2 + dz^2) * t^2  +  2 * (ax * dx+ay * dy+az * dz) * t + ax^2 + ay^2 + az^2 - r^2 <= 0

接下来就是简单的高中求范围问题了通过判别式b^2 - 4*a *c

同时注意b^2 - 4*a *c>0的时候我们要求的时间t一定是大于0的,如果较大解都小于0了那么这只蚊子就是不符合的,如果仅仅是较小解小于零,让它等于0即可

求出能进入这个球体的每个蚊子的l,r区间后,那么就变成经典的贪心问题,区间选点问题,把每个区间的右端点进行从小到大排序,选定一开始的右端点不断往后判断之后的区间左端点是否小于确定下的右端点,如果小于说明1枪就可以都打死,如果发现左端点大于了选定右端点,就需要再打一枪了,此时更新选定的右端点,打枪次数加一

最坑的就是输入用%lf超时,用%I64d才过mmp

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100005;
const double eps = 1e-8;
struct node{
    double x,y,z;
    double dx,dy,dz;
}mosq[maxn];//蚊子的初始坐标和移动方位坐标
struct Time{
    double l,r;
}times[maxn];//蚊子在射击范围内的时间段
int n,cnt;
ll r;//射击半径
bool cmp(const Time &a,const Time &b){
    if(fabs(a.r - b.r) > eps)
        return a.r < b.r;
    return a.l > b.l;

}//先按照右边界从小到大排序,如果右边界近似相等按左边界从大到小排序
void cal(node mos,double &a,double &b,double &c){
    a = mos.dx * mos.dx + mos.dy * mos.dy + mos.dz * mos.dz;
    b = 2 * (mos.x * mos.dx + mos.y * mos.dy + mos.z * mos.dz);
    c = mos.x * mos.x + mos.y * mos.y + mos.z * mos.z - r * r;
}
double diat(double a,double b,double c){//判别式
    return b * b - 4 * a * c;
}
void solve(node mos){//solve函数是求解方程的解即蚊子在射程内的时间边界
    double a,b,c;
    cal(mos,a,b,c);//求一元二次方程系数abc
    double del = diat(a,b,c);
    if(del < 0) return; //无解,说明蚊子不会经过射程区域
    else if(del > 0){//判别式大于零两个解
        double x1 = (-1.0 * b - sqrt(del * 1.0)) / (2.0 * a);
        double x2 = (-1.0 * b + sqrt(del * 1.0)) / (2.0 * a);
        if(x2 < 0) return;//时间必须大于0;
        if(x1 < 0)
            times[cnt].l = 0.0;
        else
            times[cnt].l = x1;
        times[cnt++].r = x2;
    }
    else{//一个解
        double x = -1.0 * b / (2.0 * a);
        if(x < 0) return;
        times[cnt].l = x;
        times[cnt++].r = x;
    }
}
int main(){
    int t,cas = 0;
    scanf("%d",&t);
    while(t--){
        scanf("%d%I64d",&n,&r);
        ll x,y,z,dx,dy,dz;
        for(int i = 0; i < n; i++){
            scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&x,&y,&z,&dx,&dy,&dz);
            mosq[i].x = x * 1.0;
            mosq[i].y = y * 1.0;
            mosq[i].z = z * 1.0;
            mosq[i].dx = dx * 1.0;
            mosq[i].dy = dy * 1.0;
            mosq[i].dz = dz * 1.0;
        }
        cnt = 0;//能进入区域的蚊子数
        for(int i = 0; i < n; i++){
            solve(mosq[i]);
        }
        sort(times,times+cnt,cmp);
        int ans = 1;
        double bound = times[0].r;
        for(int i = 1; i < cnt; i++){
            if(times[i].l > bound){
                ans++;
                bound = times[i].r;
            }
        }
        if(cnt == 0)
            printf("Case %d: 0 0\n",++cas);
        else
            printf("Case %d: %d %d\n",++cas,cnt,ans);
    }
    return 0;
}

实现真正的「人机」对战:引入三方 AI 引擎 引入三方 AI 引擎 前边,我们实现了与云库对战的象棋游戏。这一节中,我们将开始实现真正的「人机」对战 — 人与手机 AI 之间对弈; 实现一套象棋 AI 工程浩大,这个工作我们后续文章会做一番介绍。现代软件工程并不主张每个人都「造轮子」,因此我们要有「站在巨人肩膀上」的小智慧。 本节概要 从 github 寻找开源中象引擎 梳理引擎接入的思路 寻找适合的开源中国象棋引擎 github 上有大... 阅读详情

相关推荐

工业数据采集实战:用open62541库读写PLC的OPC UA节点(避坑指南)

本文详细介绍了如何使用open62541库实现工业PLC的OPC UA节点数据采集,涵盖环境搭建、节点读写优化及生产环境故障排查。通过订阅模式和多节点读写技术,显著提升数据采集效率与稳定性,适用于智能制造和工业物联网场景。

weixin_30598225的博客 398

flash 小游戏大全

http://www.xiaoyouxi.com/http://www.4399.com/http://yule.sohu.com/flashgame.shtml   Flash游戏-最新FLASH-极酷动漫-搜狐娱乐

xubaogongChina的专栏 2万+

Windows 11 IoT企业版LTSC 24H2/25H2中文版安装指南(含OEM激活教程)

本文详细介绍了Windows 11 IoT企业版LTSC 24H2/25H2中文版的安装与OEM激活全流程。从系统镜像准备、硬件兼容性检查到自动化安装配置,再到OEM激活方案(包括SLIC注入和数字许可证激活),为工业自动化、数字标牌等物联网设备提供稳定可靠的系统部署指南。

weixin_29198045的博客 8802

【期望】fuzoj 2265 Card Game (Second Edition)

http://acm.fzu.edu.cn/problem.php?pid=2265

Hi_jiaxinwei的博客 7024

避开封号风险!wxauto+Claude API实现微信智能客服的合规方案

本文详细介绍了如何利用wxauto和Claude API构建合规的微信智能客服系统,避免封号风险。通过技术选型对比、防封策略设计及大模型接入实践,为企业提供了一套安全高效的解决方案,特别适合中小企业在微信生态中部署AI客服。

sql99的博客 445

2026年全国青少年信息素养大赛算法应用主题赛C++样题及答案解析

2026年全国青少年信息素养大赛算法应用主题赛C++样题

王老师青少年编程 3711

FZU 2264 Card Game (First Edition)(数学概率题)

Problem 2264 Card Game (First Edition) Accept: 114    Submit: 343 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (

qq_37164003的博客 623

MCU-内部flash模拟成EepRom(重新梳理)

通过fee写数据Data的过程中,数据会mapping一个虚拟地址,这个虚拟地址就是你的身份,在向flash写数据的过程中会写入很多相同虚拟地址的不同数据,在读取或切页的过程中,遍历数据只会认为最下面第一个的虚拟地址所持有的数据是有效数据,其他的都是老数据,可以丢弃。模拟成eeprom的两个eep_page写数据逻辑就是,先在eep_page0写数据,eep_page0写满后,将eep_page0的有效数据copy到eep_page1,之后擦eep_page0;

xiandang8023的博客 711

OOXX Game

Think: 这次组队赛的水题。。。。 判断 O 是奇数还是偶数 然后对应输出就可以了~~~Problem DescriptionFat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, there are N

不积跬步,无以至千里 1万+

dex2oat编译优化调试

dex2oat编译调试的一些技巧和方法

jidapenglin28的专栏 5044

海康威视 2024届 数字逻辑设计 实习笔试分析

记录一下 5月11日晚,做的海康威视的一场笔试。分享给需要的IC人。 岗位:数字逻辑设计工程师(浙江 杭州) 转载需要本人同意! 我的见解不一定都是准确的,欢迎评论区交流指正~~

记录所学,分享知识,结识挚友 1万+

FZU_Problem 2151 OOXX Game

Problem 2151 OOXX Game Accept: 476    Submit: 730 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) game on

有一种力量叫乐观 1678

C++(Qt)软件调试---gdb调试入门用法(12)

学习GDB可以帮助程序员更好地调试程序,找到程序中的错误和问题,提高程序的质量和稳定性。 在开发大型软件时,程序中可能存在许多错误和问题,这些问题可能会导致程序崩溃或者出现不可预期的行为。 使用GDB可以帮助程序员更快地找到这些问题,并且提供一些调试工具来帮助程序员更好地理解程序的行为。

mahuifa的博客 5544

fzu 2144 Shooting Game(贪心区间覆盖)

题目链接:fzu 2144 Shooting Game 题目大意:在立体的空间上,有n只蚊子,给出蚊子的坐标,以及蚊子的移动方向(向量的方式给出), 然后人的攻击范围为半径为r的球体。问说人最多可以打几只蚊子,以及需要花多少时间。 解题思路:对于每只蚊子计算进入攻击范围的时间和离开攻击范围的时间,注意有可能不进入攻击空间,计算区间可以设一个k然后解方程求出区间,然后对求出的区间

不慌不忙、不急不躁 1808

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

fzu 2144 Shooting Game 区间覆盖贪心

题意:一个人在空间直角坐标系的原点,即是(0,0,0), 他的射程范围是以R为半径的球体,有n只蚊子,每只蚊子都会有原始坐标和三个坐标方向的速度,人要尽量把多的蚊子射下来,并且开枪次数最少。 思路:假设一只蚊子能进入这个球体,必然有一个进入时间和离开时间,我们设为t,蚊子当前坐标为x = ax + dx * t, y = ay + dy * t, z = az + dz * t, 通过两

zyh 681

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

FZU - 2144 Shooting Game(贪心,区间覆盖问题变题)

Problem 2144 Shooting Game Accept: 267    Submit: 1368 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Fat brother and Maze are playing a kind of special (hentai) gam

luciozhang的博客 1119

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

FZU 2144 Shooting Game(球体方程和直线方程联立+贪心区间覆盖)

Shooting Game Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (Maybe it’s the OOXX game which decrypted in the last problem, who knows.) But a

piaocoder 619

FZU 2148 Moon Game

Description Fat brother and Maze are playing a kind of special (hentai) game in the clearly blue sky which we can just consider as a kind of two-dimensional plane. Then Fat brother starts to draw N

fuckohmylove的专栏 7714

A-B Game 水题+longlong

题目来源:http://acm.fzu.edu.cn/contest/problem.php?cid=134&sortid=8 Problem H A-B Game Accept: 103Submit: 237Time Limit: 1000 mSecMemory Limit : 32768 KB Problem Description Fat...

weixin_33816821的博客 278

Unity动漫游戏集合

Unity动漫游戏集合 MONMUSU 喜歡魔物女孩的你 作為國家的年輕氣盛新手召喚師 努力賺錢買齊召喚材料, 累積人品召喚出魔物女孩吧! わがままアリスと百日戦争 -Brutal Alice and the Hundred Day's War- 地域制压型战略模拟游戏。这是一款争夺地图上104个据点的战略游戏。 本作没有课金要素可以免费游玩。 Crush C...

aerou的博客 2047

Fire Game

Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty

笑看风云起的专栏 1208

fzu-2266

C - Card Game (Third Edition)   Fat brother and Maze are playing a kind of special (hentai) game with some cards. In this game, every player gets N cards at first and these are their own card deck

yu121380的博客 487

Flash game 女生的遊戲

女生的遊戲

菜菜专栏 4377

B OOXX Game(FZU 2151)

B  OOXX Game Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, there are N*M coins in this board with two symbol “O” or “X”. Th

YOONGI 1万+

FZU-2148-Moon Game

I - Moon Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatusPracticeFZU 2148 Description Fat brother and Maze are playing a kind of special (hentai) game

Prim 2224

欧美html游戏安卓,HTML5 Games - Rated M or for 18+ only

Thanks for sharing. I was always interested in entering adult games market, since I've got pretty wild imagination and all this stuff is like a second nature to me.What types of games are you guys int...

weixin_35806032的博客 1万+
上一篇: Simple String Problem FZU - 2218 (状压dp)
下一篇: Seating of Students (dfs模拟+思维)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值