csu1377Putter && HOJ12816
链接:(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的更多相关文章
随机推荐
- python的Socket网络编程 使用模板
本文给出的是TCP协议的Socket编程. 其中用了一个dbmanager数据库操作模块,这个模块是我自己定义的,可以在我的另一个文章中找到这个模块的分享.python操作mysql数据库的精美实用模 ...
- [!] Attempt to read non existent folder `***********`
以前遇到过的问题,最近又出现了,问题单独列出,容易查找: $ pod install [!] Attempt to read non existent folder `/Users/galahad/D ...
- Structs2笔记③--局部类型转换案例
Structs2的类型转换-局部类型转换 Ognl强大的表达式语言,在导入项目的时候我们导入了ognl.jar包,内有TypeConverter类,struct主要依赖于他进行类型转换. 例子 i ...
- IHttpModule理解-知识补充
文章:IHttpModule的那些事 可以自定义类实现IHttpModule接口,然后实现接口方法Init,Init方法可以得到HttpApplication 的实例化对象. 然后给对象的事件的注册各 ...
- 【CSAPP笔记】14. 异常控制流和进程
从给处理器加电,到断电为止,处理器做的工作其实就是不断地读取并执行一条条指令.这些指令的序列就叫做 CPU 的控制流(control flow).最简单的控制流是"平滑的",也就是 ...
- python字符串操作、文件操作,英文词频统计预处理
1.字符串操作: 解析身份证号:生日.性别.出生地等. 凯撒密码编码与解码 网址观察与批量生成 解析身份证号:生日.性别.出生地等 def function3(): print('请输入身份证号') ...
- 《软件工程和Python》第0周作业1
写在前面的话 欢迎大家开始一段新的课程学习!从开博客开始吧.每次博客作业都会有评分,计入总成绩哦. 1. 截止日期 本次作业的提交截止时间:见老师要求 2. 作业要求 (1)建立个人技术博客和 ...
- grunt入门讲解7:项目脚手架grunt-init
grunt-init是一个用于自动创建项目脚手架的工具.它会基于当前工作环境和你给出的一些配置选项构建一个完整的目录结构.至于其所生成的具体文件和内容,依赖于你所选择的模版和构建过程中你对具体信息所给 ...
- 【第七周】B-1分数发布
组名: 新蜂 组长: 武志远 组员: 宫成荣 谢孝淼 杨柳 李峤 项目名称: java俄罗斯方块 由于排名信息过于敏感,由以下方式进行. 宫成荣 = 魑,谢孝淼 = 魅,武志远 = 魉,杨柳 = ...
- cmd命令行安装,删除Windows证书(certgmr的简单使用)
在管理证书的时候需要用到certmgr工具. 在cmd中执行certmgr会弹出证书管理的工具,但是不能用命令行去管理证书,需要额外的工具 cermgr.exe:下载链接 https://pan.ba ...