fzu 2144 Shooting Game(贪心区间覆盖)
来源:互联网 发布:淘宝客营销计划佣金 编辑:程序博客网 时间:2024/05/20 17:25
题目链接:fzu 2144 Shooting Game
题目大意:在立体的空间上,有n只蚊子,给出蚊子的坐标,以及蚊子的移动方向(向量的方式给出), 然后人的攻击范围为半径为r的球体。问说人最多可以打几只蚊子,以及需要花多少时间。
解题思路:对于每只蚊子计算进入攻击范围的时间和离开攻击范围的时间,注意有可能不进入攻击空间,计算区间可以设一个k然后解方程求出区间,然后对求出的区间做区间覆盖问题。
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>using namespace std;const int N = 100005;const double eps = 0;inline bool scan_d(double &ret) { char c; int sgn; if(c = getchar(),c == EOF) return 0; //EOF while(c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret *= sgn; return 1; } struct point {double x, y, z;void get() { scan_d(x); scan_d(y); scan_d(z); }};struct state {double x, y;}s[N];int n, tmp;double r;void add(point p, point q) {double a = q.x * q.x + q.y * q.y + q.z * q.z;double b = 2 * (p.x * q.x + p.y * q.y + p.z * q.z);double c = p.x * p.x + p.y * p.y + p.z * p.z - r * r;double t = b * b - 4 * a * c;if (t < 0) return;else if (t == 0) {double i = -b / (2.0 * a);if (i < 0) return;s[tmp].x = s[tmp].y = i;}else {double i = (-b + sqrt(t) ) / (2 * a);double j = (-b - sqrt(t) ) / (2 * a);if (i < 0 && j < 0) return;else if (i < 0) i = 0;else if (j < 0) j = 0;s[tmp].x = min(i, j);s[tmp].y = max(i, j);}tmp++;}void init() {tmp = 0;point p, q;scanf("%d%lf", &n, &r);for (int i = 0; i < n; i++) {p.get(); q.get();add(p, q);}}bool cmp(const state& a, const state& b) {if (fabs(a.y - b.y) > eps) return a.y - b.y < eps;return a.x - b.x < eps;}int solve() {int ans = 0;double c = -1;for (int i = 0; i < tmp; i++) {if (s[i].x - c > eps) {c = s[i].y;ans++;}}return ans;}int main () {int cas;scanf("%d", &cas);for (int i = 1; i <= cas; i++) {init();sort(s, s + tmp, cmp);printf("Case %d: %d %d\n", i, tmp, solve());}return 0;}
1 0
- fzu 2144 Shooting Game(贪心区间覆盖)
- fzu 2144 Shooting Game 区间覆盖贪心
- FZU - 2144 Shooting Game(贪心,区间覆盖问题变题)
- FZU 2144 Shooting Game(球体方程和直线方程联立+贪心区间覆盖)
- FZU 2144 Shooting Game(几何 + 贪心区域覆盖)
- FZU 2144 Shooting Game
- FZU 2144 —— Shooting Game (贪心)
- FZU 2144 Shooting Game (贪心区域划分)
- FZU Problem 2144 Shooting Game
- FZU 2144(几何+贪心区间覆盖)
- FZU 2144 Shooting Game(计算几何)
- Problem 2144 Shooting Game
- 贪心之区间覆盖
- 贪心区间覆盖--poj2378
- 区间覆盖问题【贪心】
- 区间覆盖问题 贪心
- 贪心 区间覆盖问题
- 区间覆盖问题(贪心)
- 学习dbms_xplan_display_awr
- 1.HTML5简介
- 算法之旅,直奔<algorithm>之二十三 none_of
- ASCII与Unicode
- 软件设计原则之单一职责原则
- fzu 2144 Shooting Game(贪心区间覆盖)
- 如何完全删除vmware的方法
- Linux--Web应用服务和MySQL数据库
- 黑马程序员--Writer,Reader,Buffer(重要,但是很简单)
- Leetcode: Plus One
- SBT
- 我心中的信合 企业征文
- Notepad++使用技法
- C#学习4