链接:(csu)http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1377

   (HOJ)http://49.123.82.55/online/?action=problem&type=list&courseid=0&querytext=&pageno=57

题意:

  给定凸多边形的点(按顺时针),多边形内一点沿某个方向运动,碰到边进行镜面反射,问在一条边不碰超过两次的情况下,有多少种不同的碰撞方法。多边形最多8条边。

思路:

  枚举每一种情况,合理就对结果+1,枚举用dfs轻松加愉快。本题关键在于求出镜像点,然后以镜像点出发,对边进行考察,若能直线到达,则该点能被反射到,否则不能。

Code:

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define op operator
#define cp const P&
#define cn const
#define db double
#define rt return
using namespace std;
cn db eps = 1e-;
cn db pi = acos(-1.0);
inline int sig(db x) {return (x>eps) - (x<-eps);} struct P{
db x, y;
P(db a = 0.0, db b = 0.0) : x(a), y(b) {}
void in() { scanf("%lf %lf", &x, &y);}
void out(){ printf("%lf %lf\n", x, y);}
bool op<(cp a)cn {return sig(x-a.x) ? sig(x-a.x) : sig(y-a.y);}
P op-(cp a)cn {return P(x-a.x, y-a.y);}
P op+(cp a)cn {return P(x+a.x, y+a.y);}
db op^(cp a)cn {return x*a.y - y*a.x;}
db cross(P a, P b) {return (a-*this) ^ (b-*this);}
db op*(cp a)cn {return x*a.x + y*a.y;} //点积
db dot(P a, P b) {return (a-*this) * (b-*this);}
P op*(cn db &a)cn {return P(a*x, a*y);}
bool op/(cp a)cn {return sig(x*a.y - y*a.x) == ;}
db dis() {return sqrt(x*x + y*y);}
db dis(P a) {return (a-*this).dis();}
P T() {return P(-y, x);}
P roate(db d) {
return P(x*cos(d) - y*sin(d), y*cos(d) + x*sin(d));
}
bool on(P a, P b) {return !sig(cross(a, b)) && sig(dot(a, b)) <= ;} //点在线段上
P Mirror_P(P a, P b) {
P v1 = *this - a, v2 = b - a;
db w = acos(v1*v2 / v1.dis() / v2.dis());
int f = sig(v1^v2);
w = *w*f;
rt a + v1.roate(w);
}
}p[], q;
inline P inset(P a1, P b1, P a2, P b2) {
db u = (b1^a1), z = b2^a2, w = (b1-a1) ^ (b2-a2);
P v;
v.x = ((b2.x-a2.x)*u - (b1.x-a1.x)*z) / w;
v.y = ((b2.y-a2.y)*u - (b1.y-a1.y)*z) / w;
rt v;
}
bool vis[];
int ans, n;
bool if_insight(P q, int i, P a, P b) {
if(sig(q.cross(b, p[i])) <= && sig(q.cross(b, p[i+])) <= ) rt false;
if(sig(q.cross(a, p[i])) >= && sig(q.cross(a, p[i+])) >= ) rt false;
rt true;
}
void dfs(P q, int k, int m, P a, P b) {
if(vis[k]) rt ;
if(m == n) { ++ans; rt ; }
vis[k] = ;
q = q.Mirror_P(p[k], p[k+]);
for(int i = ; i < n; ++i) {
if(i != k && if_insight(q, i, a, b)) {
P c , d;
if(sig(q.cross(b, p[i])) < ) c = inset(b, q, p[i], p[i+]);
else c = p[i];
if(sig(q.cross(a, p[i+])) > ) d = inset(a, q, p[i], p[i+]);
else d = p[i+]; dfs(q, i, m+, c, d);
}
}
vis[k] = ;
}
void solve() {
p[n] = p[];
ans = ;
for(int i = ; i < n; ++i)
dfs(q, i, , p[i], p[i+]);
printf("%d\n", ans);
rt ;
}
int main()
{
while(scanf("%d", &n), n) {
q.in();
for(int i = ; i < n; ++i) p[i].in();
memset(vis, , sizeof vis);
solve();
}
return ;
}

csu1377Putter && HOJ12816的更多相关文章

随机推荐

  1. react-native ListView 性能问题

    常见性能问题已经有很多答案,这里要说的是使用ListView时注意的地方,    ListView的容器需要设定一个固定高度, 不然ListView中的item过多,会把整体页面撑开,设置的 remo ...

  2. How to submit a package to PyPI

    How to submit a package to PyPI The other month a coworker of mine wanted to distribute a small wrap ...

  3. 2-Fourth Scrum Meeting20151204

    任务安排 闫昊: 今日完成:设计本地数据库. 明日任务:请假.(最近代码写得多……很累……) 唐彬: 今日完成:ios客户端代码的了解. 明日任务:ios客户端代码的深度学习. 史烨轩: 今日完成: ...

  4. web12 使用map型的request、session、application

    电影网站:www.aikan66.com 项目网站:www.aikan66.com 游戏网站:www.aikan66.com 图片网站:www.aikan66.com 书籍网站:www.aikan66 ...

  5. Good Time 冲刺 一

    2018/6/14 我们组之前没有开发小程序的经验,所以在尝试中不断探索与学习.在完成小程序的初步注册和界面完善后,我们组开始进行开发任务. 1.1成员简述: 王怡镔:“今天主要学习小程序开发知识及相 ...

  6. LCA(最近公共祖先)算法

    参考博客:https://blog.csdn.net/my_sunshine26/article/details/72717112 首先看一下定义,来自于百度百科 LCA(Lowest Common ...

  7. [转帖]InfiniBand技术和协议架构分析

    InfiniBand技术和协议架构分析 2017年06月06日 20:54:16 Hardy晗狄 阅读数:15207 标签: 云计算存储Infiniband 更多 个人分类: 存储云计算   版权声明 ...

  8. 半夜思考之查漏补缺 , Spring 中 Bean 之间的依赖问题

    每次看书都会发现自己的不足 . 当一个 singten 的 Bean 依赖一个 prototype 的 Bean 时 , 如果不加注意 , 会发生一些奇怪的事情 , prototype 变为了 sin ...

  9. C# 源码计数器

    设计背景 编程工作中,有些文档需要填写代码量,例如申请软件著作权.查阅相关资料之后,编写了这个小程序. 设计思路 主要思路为分析项目文件,根据项目文件查找代码文件,然后遍历代码文件进行分析 相关技术 ...

  10. 关于OpenGL游戏全屏模式的设置

    使用DirectX的API的话可以给游戏窗口设置指定的显示器和全屏独占模式,但是如果使用OpenGL的API就比较遗憾不能直接设置. 以下内容基于Windows系统. 如果使用OpenGL渲染,第一步 ...