链接:(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. Redux 入门教程(一):基本用法

    转自http://www.ruanyifeng.com/blog/2016/09/redux_tutorial_part_one_basic_usages.html(仅供个人学习使用) 首先明确一点, ...

  2. 利用cocoapods创建基于git的私有库Spec Repo

    上一篇文章记录了我利用cocoapods创建基于SVN的私有库的全部过程,今天我再记录一下基于git创建的过程. 整体先说明一下创建一个私有的podspec包括如下那么几个步骤: 创建并设置一个私有的 ...

  3. OO第二阶段作业总结

    第五次作业:         设计策略: 本次作业设计的基本思路是按照指导书所给的推荐方法来完成的,即共用对象为队列盘,线程有电梯.调度器.以及扫描器,扫描器将控制台输入的有效指令加入到队列盘中,调度 ...

  4. Chapter 4 需求工程

    软件需求是用户解决问题或达到目的所需的条件或能力,以及系统或系统部件要满足合同.标准.规范或其他正式规定文档所需要的条件和能力.软件需求可以划分为业务需求.用户需求.系统需求.功能需求和非功能需求等类 ...

  5. 微服务负载均衡 —— ribbon

    负载均衡是系统高可用.缓解网络流量和处理能力扩容的重要手段,广义的负载均衡指的是服务端负载均衡,如硬件负载均衡(F5)和软件负载均衡(Nginx).负载均衡设备会维护一份可用的服务器的信息,当客户端请 ...

  6. [图的遍历&多标准] 1087. All Roads Lead to Rome (30)

    1087. All Roads Lead to Rome (30) Indeed there are many different tourist routes from our city to Ro ...

  7. 搭建企业级Docker Registry -- Harbor

    Harbor 是一个企业级的 Docker Registry,可以实现 images 的私有存储和日志统计权限控制等功能,并支持创建多项目(Harbor 提出的概念),基于官方 Registry V2 ...

  8. [转帖]IBM POWER9 E950 and E980 Servers Launched

    IBM POWER9 E950 and E980 Servers Launched https://www.servethehome.com/ibm-power9-e950-and-e980-serv ...

  9. linux ls文件颜色和底色设置

    转帖 :linux ls文件颜色和底色设置 白色:表示普通文件蓝色:表示目录绿色:表示可执行文件红色:表示压缩文件浅蓝色:链接文件红色闪烁:表示链接的文件有问题黄色:表示设备文件灰色:表示其他文件 这 ...

  10. springboot学习笔记-2 一些常用的配置以及整合mybatis

    一.一些常用的配置 1.1 使用没有父POM的springboot 通过添加scope=import的依赖,仍然能获取到依赖管理的好处: <dependencyManagement> &l ...