fzu 2144 Shooting Game(貪心區間覆蓋)

來源:互聯網
上載者:User


#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;}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.