链接:(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. python的Socket网络编程 使用模板

    本文给出的是TCP协议的Socket编程. 其中用了一个dbmanager数据库操作模块,这个模块是我自己定义的,可以在我的另一个文章中找到这个模块的分享.python操作mysql数据库的精美实用模 ...

  2. Scrum Meeting 5 -2014.11.11

    放假过掉一大半.大家都努力赶着进度,算法实现基本完成.可能还有些细小的改动,但也可以统一进入测试阶段了. 今天叫了部分在校人员开了个小会.任务决定以测试为主,同时开始进行服务器的部署. 在之前尝试服务 ...

  3. Linux 目录结构及文件基本操作

    Linux 目录结构及文件基本操作 实验介绍 1.Linux 的文件组织目录结构. 2.相对路径和绝对路径. 3.对文件的移动.复制.重命名.编辑等操作. 一.Linux 目录结构 在讲 Linux ...

  4. XCODE的演变及使用经验分享

    IOS编程使用的是XCODE 编译器,安装XCODE你需要一台MAC(黑苹果也可以,个人不推荐,不稳定),然后直接去MAC上的APP STORE上下载安装就行,很简单,再次不做过多介绍... OK,那 ...

  5. angularJS1笔记-(10)-自定义指令(templateUrl属性)

    index.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  6. Enterprise Library 4.1 参考源码索引

    http://www.projky.com/entlib/4.1/Microsoft/Practices/EnterpriseLibrary/AppSettings/Configuration/Des ...

  7. 微信小程序demo——入门级(附源码)

    最近小程序又蠢蠢欲动,出了一个公众号绑定小程序功能,目测不错,就看了下微信小程序文档,顺便写了几行代码,后续有空会持续更新维护. 源码:https://github.com/SibreiaDante/ ...

  8. php手册 | python手册 | perl手册 | c#.net手册 | c++手册 | ruby手册 | jquery手册 | js手册 | prototype手册 | mysql手册 | smarty手册 | css手册 | html手册 | nginx手册 | apache手册 | shell手册 | svn手册

    收集各种实用类手册: http://shouce.jb51.net/shell/

  9. nilcms file类 简单文件缓存实现

    实现简单的文件缓存,参照CI的部分设计,在这里记录一下子. class File { const CACHE_PATH = 'nil_file_cache'; /*其他函数省略了*/ /** * 获取 ...

  10. Avito Cool Challenge 2018 自闭记

    A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...