Beam Cannon
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 225 Accepted Submission(s): 87
Problem Description
Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaceships is approaching. There is a very large Beam Cannon on the Planet X, and it is very powerful, which can destroy all the spaceships in its attack range in a second. However, it takes a long time to fill the energy of the Beam Cannon after each shot. So, you should make sure each shot can destroy the enemy spaceships as many as possible.
To simplify the problem, the Beam Cannon can shot at any area in the space, and the attack area is rectangular. The rectangle parallels to the coordinate axes and cannot rotate. It can only move horizontally or vertically. The enemy spaceship in the space can be considered as a point projected to the attack plane. If the point is in the rectangular attack area of the Beam Cannon(including border), the spaceship will be destroyed.
To simplify the problem, the Beam Cannon can shot at any area in the space, and the attack area is rectangular. The rectangle parallels to the coordinate axes and cannot rotate. It can only move horizontally or vertically. The enemy spaceship in the space can be considered as a point projected to the attack plane. If the point is in the rectangular attack area of the Beam Cannon(including border), the spaceship will be destroyed.
Input
Input contains multiple test cases. Each test case contains three integers N(1<=N<=10000, the number of enemy spaceships), W(1<=W<=40000, the width of the Beam Cannon’s attack area), H(1<=H<=40000, the height of the Beam Cannon’s attack area) in the first line, and then N lines follow. Each line contains two integers x,y (-20000<=x,y<=20000, the coordinates of an enemy spaceship).
A test case starting with a negative integer terminates the input and this test case should not to be processed.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
Output
Output the maximum number of enemy spaceships the Beam Cannon can destroy in a single shot for each case.
Sample Input
2 3 4
0 1
1 0
3 1 1
-1 0
0 1
1 0
-1
Sample Output
2
2
题意:
给出 N,W,H,代表有 N 个点还有一个 W 长 H 高的矩形。现用这个矩形覆盖,问最多能覆盖给出的点中有多少个。
思路:
线段树 + 扫描线。以每个点作为中心,建立一个矩形范围,说明这个矩形的中心放在这个区域中,就能够覆盖这个点。在建完所有的矩形后,求某个区域被矩形覆盖最多,这个区域被矩形覆盖数即为所求。用扫描线即可求出。
AC:
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAX = 10005 * 2; typedef struct { double y1, y2, x; int temp; } node; int n, m, ans; double yy[MAX]; node no[MAX]; int cover[MAX * 5], Max[MAX * 5]; bool cmp (node a, node b) { if (a.x != b.x) return a.x < b.x; return a.temp > b.temp; } void push_down (int node) { cover[node << 1] += cover[node]; cover[node << 1 | 1] += cover[node]; Max[node << 1] += cover[node]; Max[node << 1 | 1] += cover[node]; cover[node] = 0; } void push_up (int node) { Max[node] = max(Max[node << 1], Max[node << 1 | 1]); } void updata (int node, int l, int r, int cl, int cr, int c) { if (cl > r || cr < l) return; if (cl <= l && cr >= r) { cover[node] += c; Max[node] += c; return; } push_down(node); int mid = (r + l) >> 1; if (cl <= mid) updata(node << 1, l, mid, cl, cr, c); if (cr > mid) updata(node << 1 | 1, mid + 1, r, cl, cr, c); push_up(node); } int main() { double w, h; while (~scanf("%d", &n) && n != -1) { scanf("%lf%lf", &w, &h); m = 0, ans = 0; for (int i = 1; i <= n; ++i) { double x, y; scanf("%lf%lf", &x, &y); yy[m++] = y + h / 2; yy[m++] = y - h / 2; no[ans].y1 = y - h / 2; no[ans].y2 = y + h / 2; no[ans].x = x - w / 2; no[ans++].temp = 1; no[ans].y1 = y - h / 2; no[ans].y2 = y + h / 2; no[ans].x = x + w / 2; no[ans++].temp = -1; } sort(yy, yy + m); m = unique(yy, yy + m) - yy; sort(no, no + ans, cmp); memset(cover, 0, sizeof(cover)); memset(Max, 0, sizeof(Max)); int res = 0; for (int i = 0; i < ans; ++i) { int cl = lower_bound(yy, yy + m, no[i].y1) - yy; int cr = lower_bound(yy, yy + m, no[i].y2) - yy; updata(1, 0, m - 1, cl, cr, no[i].temp); res = max(res, Max[1]); } printf("%d\n", res); } return 0; }
相关推荐
Cannon算法,由James Cannon在1969年提出,是一种用于分布式计算机系统中的矩阵乘法算法,尤其适用于处理大规模数据。它利用了二维网格计算模型,将参与运算的矩阵分布在多个处理器上,通过通信网络进行同步和数据...
在本项目中,"ThreeJS+Cannon-ES 跳一跳"是一个基于Web的3D游戏,模仿了微信小程序的热门游戏“跳一跳”。它利用了现代Web开发技术,将JavaScript库Three.js用于创建3D场景,Cannon-es处理物理模拟,Vue.js作为前端...
Cannon算法是一种经典的并行矩阵乘法策略,它利用二维网格结构来分配计算任务,有效提高了计算效率。在这个项目中,我们将深入探讨如何使用MPI(Message Passing Interface)和Boost库来实现Cannon算法。 MPI...
在前端开发领域,3D图形和物理效果的实现通常是复杂且资源密集的,但随着技术的进步,出现了像Cannon.js这样的轻量级3D物理引擎,使得这些功能可以在浏览器环境中更加便捷地实现。Cannon.js是一个用纯JavaScript编写...
cannon lide 110扫描仪 驱动
【基于Cannon.js和Three.js的3D文字特效】是一个使用现代Web技术实现的互动式图形项目,主要涉及HTML5库中的两个关键组件:Cannon.js和Three.js。这两个JavaScript库是开发3D web应用程序的强大工具,特别是对于创建...
该算法是cannon的并行算法的发送接收MPI的实现
3d模型
基于MPI的cannon算法,实现矩阵的相乘
矩阵相乘运算的cannon算法,适用于方阵间的高性能算法
【标题】:“自己根据cannon改的” 指的是用户对原有的Cannon项目进行了个性化改造,这通常意味着用户在Cannon的基础上添加或修改了一些功能,以满足特定需求。Cannon可能是一个开源项目,用于图形渲染、物理模拟或...
经典的cannon算法,主要用于矩阵相乘的并行求解问题。这个实现简单易懂,里面有详细注释。
Master-Worker模式是常用的并行设计模式。它的核心思想是,系统有两个进程协议工作:Master进程和Worker进程。Master进程负责接收和分配任务,Worker进程负责处理子任务。当各个Worker进程将子任务处理完后,将结果...
yarn add three cannon-es用法为cannon-es-debugger对您的“三场景”对象和Cannon物理物体的引用: import { Scene } from 'three'import { World } from 'cannon-es'import cannonDebugger from 'cannon-es-...
标题中的“mpi.rar_Cannon MPI_MPI OpenMP_OpenMp TSP_mpi cannon_mpi linux”揭示了这个压缩包文件包含的内容,主要涉及MPI(Message Passing Interface)和OpenMP两种并行计算技术,以及Cannon算法和旅行商问题...
Cannon算法是由James Cannon在1969年提出的一种矩阵乘法的并行算法,它主要应用于分布式内存的多处理机系统,特别是那些具有二维处理器网格结构的系统。该算法充分利用了二维网格中的对角线交换特性,有效地实现了大...
Cannon Lide25是一款由佳能(Canon)公司推出的扫描仪型号,其驱动程序是确保该设备在计算机上正常运行的关键组件。本文将详细解释关于Cannon Lide25驱动的相关知识点,包括驱动的作用、安装过程以及常见问题的解决...
通过Cannon.js,开发者可以为3D对象添加真实的物理行为,使它们在虚拟世界中遵循物理定律,增加了游戏和互动应用的真实感。 在"HTML5 WebGL+Three.js+Cannon.js实现的3D立体十字关卡碰撞动画源码.zip"这个项目中,...
MPI源文件:Cannon并行实现及加速比分析
三加农炮 将THREE.Mesh转换为CANNON.Shape,并使用简化的形状进行可选的优化。用法安装: npm install -- save three - to - cannon 进口: // ES6import { threeToCannon } from 'three-to-cannon' ;// ...