1263 -- Reflections

  简单计算几何。题目给出射线以及若干个不相交的圆,求出射线会在哪些圆上反弹,依次写出反弹球的编号。

代码如下:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector> using namespace std; const double EPS = 1e-;
template<class T> T sqr(T x) { return x * x;}
inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
bool operator < (Point a) const { return sgn(x - a.x) < || sgn(x - a.x) == && y < a.y;}
bool operator == (Point a) const { return sgn(x - a.x) == && sgn(y - a.y) == ;}
Point operator + (Point a) { return Point(x + a.x, y + a.y);}
Point operator - (Point a) { return Point(x - a.x, y - a.y);}
Point operator * (double p) { return Point(x * p, y * p);}
Point operator / (double p) { return Point(x / p, y / p);}
} ;
typedef Point Vec; inline double cross(Vec a, Vec b) { return a.x * b.y - a.y * b.x;}
inline double cross(Point o, Point a, Point b) { return cross(a - o, b - o);}
inline double dot(Vec a, Vec b) { return a.x * b.x + a.y * b.y;}
inline double dot(Point o, Point a, Point b) { return dot(a - o, b - o);}
inline double veclen(Vec x) { return sqrt(dot(x, x));}
inline Vec normal(Vec x) { return Vec(-x.y, x.x) / veclen(x);} struct Line {
Point s, t;
Line() {}
Line(Point s, Point t) : s(s), t(t) {}
Vec vec() { return t - s;}
Point pt(double x) { return s + vec() * x;}
Line move(double x) {
Vec nor = normal(vec());
return Line(s + nor * x, t + nor * x);
}
} ; inline Point llint(Point P, Vec v, Point Q, Vec w) { return P + v * (cross(w, P - Q) / cross(v, w));}
inline Point llint(Line a, Line b) { return llint(a.s, a.vec(), b.s, b.vec());} struct Circle {
Point c;
double r;
Circle() {}
Circle(Point c, double r) : c(c), r(r) {}
} ; void lcint(Line L, Circle C, vector<Point> &sol) {
Point ip = llint(L, Line(C.c, C.c + normal(L.vec())));
double dis = veclen(ip - C.c);
if (sgn(dis - C.r) >= ) return ;
Vec u = L.vec() / veclen(L.vec());
double d = sqrt(sqr(C.r) - sqr(dis));
sol.push_back(ip + u * d);
sol.push_back(ip - u * d);
} Point reflect(Point x, Line L) {
Vec nor = normal(L.vec());
Point ip = llint(L, Line(x, x + nor));
return ip + ip - x;
} vector<Circle> rec;
Point src;
Vec dir; const double FINF = 1e100;
inline bool onCircle(Point p, Circle c) { return sgn(veclen(p - c.c) - c.r) == ;} void work() {
int cnt = , sz = rec.size();
vector<Point> tmp;
Point ip;
while (true) {
tmp.clear();
double d = FINF;
for (int i = ; i < sz; i++) lcint(Line(src, src + dir), rec[i], tmp);
for (int i = , sz = tmp.size(); i < sz; i++) {
double t = (tmp[i].x - src.x) / dir.x;
if (t > EPS) d = min(d, t);
}
if (sgn(d - FINF) >= ) break;
cnt++;
if (cnt > ) break;
ip = src + dir * d;
int mk = -;
for (int i = ; i < sz; i++) if (onCircle(ip, rec[i])) { mk = i; break;}
if (mk == -) { puts("shit!!"); while () ;}
printf("%d ", mk + );
dir = reflect(src, Line(ip, rec[mk].c)) - ip;
src = ip;
}
if (cnt > ) puts("...");
else puts("inf");
} int main() {
// freopen("in", "r", stdin);
int cas = , n;
double x, y, r;
while (cin >> n && n) {
rec.clear();
while (n--) {
cin >> x >> y >> r;
rec.push_back(Circle(Point(x, y), r));
}
cin >> src.x >> src.y;
cin >> dir.x >> dir.y;
dir = dir / veclen(dir);
printf("Scene %d\n", cas++);
work();
puts("");
}
return ;
}

  速度好慢,整整写了一个小时。对几何模板还是不算非常熟悉,虽然已经能够灵活写出部分基础函数了,但是速度还真是一个大问题。最后结果,因为手多血多个换行PE了一次,然后就AC了~

——written by Lyon

poj 1263 Reflections (Simple Geometry)的更多相关文章

  1. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  2. POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)

    POJ 3468.A Simple Problem with Integers 这个题就是成段的增减以及区间查询求和操作. 代码: #include<iostream> #include& ...

  3. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

  4. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  5. poj 3468:A Simple Problem with Integers(线段树,区间修改求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 58269   ...

  6. poj 3468 A Simple Problem with Integers 线段树第一次 + 讲解

    A Simple Problem with Integers Description You have N integers, A1, A2, ... , AN. You need to deal w ...

  7. POJ 3922 A simple stone game

    题目: E - A simple stone game Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d &am ...

  8. POJ 3468 A Simple Problem with Integers //线段树的成段更新

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 59046   ...

  9. [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]

    A Simple Problem with Integers   Description You have N integers, A1, A2, ... , AN. You need to deal ...

随机推荐

  1. JavaScript模式:字面量和构造函数

    本篇主要讨论了通过字面量以构造对象的方法,比如对象.数组以及正则表达式等字面量的构造方法,同时还讨论了与类似Object()和Array()等内置构造函数相比,为什么基于字面量表示法是更为可取. 对象 ...

  2. MyEclipse编写ExtJS卡死问题解决方法

    MyEclipse 8.6  在 jsp 中编写 ExtJS时,会出现卡死现象,让人甚是头疼.网上找了很多方法,折腾半天,还是不管用. 什么MyEclipse 优化,Validation 取消,MyE ...

  3. 安装docker报错问题

    安装docker容易出现错误的几种情况: 1.网络问题,无法下载完成的docker容器 2.linux内核版本必须是3.10及以上 3.可以选择使用aliyun的yum源,更好用 4.

  4. 备考2019年6月份PMP考试-分享一些考试笔记(二)

    最新比较经典的100道试题,有备考的小伙伴可以练练手,文章末尾附答案. 1     一个项目经理在运作一个数据中心安装项目.他发现相关方很恼火,因为他超出了预算,原因是人员费用要高于原先的计划.另外项 ...

  5. 第三方数据库管理工具Navicat使用教程

    一.Navicat Premium是一个功能强大的第三方数据库管理工具,可以连接管理MySQL.Oracle.PostgreSQL.SQLite 及 SQL Server数据库. 使用Navicat软 ...

  6. Centos7搭建Django出现的问题(Centos7+Django1.11.1+Nginx+uwsgi)

    出现的问题: 1.pip未安装:http://www.cnblogs.com/fnng/p/3737964.html 2.安装uwsgi失败,因为未安装python-devel yum search ...

  7. js单选按钮的默认值

    function SelectWindow(str) { initradio('PhysiotherapyOptionsTable.Sex',sex);       } function initra ...

  8. SPSS函数之期和时间函数

    SPSS函数之期和时间函数 CTIME.DAYS(timevalue)数值.返回 timevalue 中的天数(包括有小数位的天数),timevalue 必须为时间格式的数值或表达式,如 TIME.x ...

  9. DFS-生日蛋糕

    生日蛋糕 一道深搜题,看了这两个博客才懂的. http://blog.csdn.net/blesslzh0108/article/details/53486168 http://blog.csdn.n ...

  10. Java练习 SDUT-2499_数字

    数字 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 定义f(x) = {比x小,不可以被x整除并且不和x互质的数的个数 ...