UVa - 12617 - How Lader
先上题目:
How Lader |
Lader is a game that is played in a regular hexagonal board (all sides equal, all angles are also equal). The game is much similar as pool game. But there is only one hole that is situated in the center of the hexagon. The position of the board is given by a 2D co-ordinate system. The top and bottom sides of the hexagon are parallel to x axis. The center of the hexagonal board is situated at (0,0).
You are trying to hit the ball B1 and the direction of hitting is from B1 to B2. After you have hit the ball B1, it starts reflecting on the walls of the hexagonal Lader board. The initial speed of the ball is given. When a ball hits a wall, its speed decreases by 1 unit/second. The ball stops when its' speed becomes 0unit/second.
You have to determine the final speed of the ball when it falls through the hole. If the ball stops before reaching the hole, print `Stops'. In this problem assume the followings:
- There is no loss of speed while rolling freely on the board.
- The radius of the ball is so small that you can consider it as a point.
- You may consider the ball fallen in the hole, if at any point the ball is situated at a distance closer than r + 10-6 units from the center of the hole, where r is the radius of the hole.
- The reflection happens according to the standard reflection rule (incident angle = reflection angle, with respect to the side of the hexagon) except for the case when it hits the corner. That case is described in 5-th rule.
- If a ball reaches at the corner (intersection point of two sides), its speed decreases by 2 (it is assumed that it hits both the walls) and it comes back along the line it hits that corner. If a ball with speed 1 hits the corner, it stops there.
The picture on the right above shows the movements of a ball on a Lader board. The numbers written denote the order of appearance.
Input
The first line of the input denotes T ( 1T
150), the number of test cases to follow. Each test case consists of a 6 integers, s ( 0 < s < 150), x1, y1, x2, y2, r, t (1
t
500). Here, s denotes the length of sides of the hexagon centered at (0,0).
(x1, y1) and (x2, y2) denote the position of ball B1 and ball B2 respectively. The balls will be strictly inside the hexagonal board. r denotes the radius of the hole, centered at (0,0). The hole resides strictly inside the hexagonal board. t denotes the initial speed of the ball.
Output
For each input, you have to print the case number first, followed by the terminal speed when it falls in the hole. If the ball stops before falling in the hole, print `Stops'.
Sample Input
- 4
- 80 10 0 20 0 5 200
- 51 7 4 0 9 5 1
- 55 -5 8 -6 7 8 104
- 12 1 0 0 -1 1 271
Sample Output
- Case 1: 198
- Case 2: Stops
- Case 3: 99
Problemsetter: Anna Fariha
Special Thanks: Md. Mahbubul Hasan
题意:给你一个正六边形,中间有一个半径为R的洞,现在有一个球b1给他一个方向向量以及速度。球每一次碰撞六边形的边速度会减1,如果撞到角的话速度会减2,问你当球掉进洞里的时候速度是多少,如果还没有掉进洞里速度就小于等于0的话就输出"Stops"。
几何+模拟。
判断射线是否穿过点,射线与线段相交,射线与圆的交点,以及向量的反射。这要这些都解决的话就没有太多问题了。
关于射线穿过点,射线与线段相交等,可以看一下该博客的一份几何模板。这里讲一下射线与圆的相交判断,射线与圆相交或者相切,可以用过解二元一次方程得到,根据判别式的值我们可以判断蛇蝎和圆的相交情况。这与向量的反射这里给出一条公式:v'=v+N*2*fabs(Dot(v,N)),其中这里v是入射向量v'是出射向量,N是反射面的法线向量,Dot(v,N)是点积。这里需要注意的是求点积以后需要求绝对值,因为这里求点积的作用是为了求向量在法线上的投影长度,所以需要转成正数。
需要注意的地方是对于起点来说,如果一开始它就在原的里面或者边上的话,那它就一开始就可以输出结果了(特别注意的是在边上的情况)。
上代码:
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <algorithm>
- #define MAX 10
- using namespace std;
- const double PI=*acos();
- const double der60=PI/;
- const double eps=1e-;
- const double sqrt3=sqrt();
- int dcmp(double x){
- if(fabs(x)<eps) return ;
- return x> ? : -;
- }
- typedef struct Point{
- double x,y;
- Point(double x=,double y=):x(x),y(y){}
- }Point;
- typedef Point Vector;
- Vector operator + (Point A,Point B){ return Vector(A.x+B.x,A.y+B.y);}
- Vector operator - (Point A,Point B){ return Vector(A.x-B.x,A.y-B.y);}
- Vector operator * (Point A,double e){ return Vector(A.x*e,A.y*e);}
- Vector operator / (Point A,double e){ return Vector(A.x/e,A.y/e);}
- bool operator == (Point A,Point B){ return dcmp(A.x-B.x)== && dcmp(A.y-B.y)==;}
- double Dot(Vector A,Vector B){ return A.x*B.x+A.y*B.y;}
- double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}
- double Length(Vector A){ return sqrt(Dot(A,A));}
- Vector Rotate(Vector A,double rad){
- return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
- }
- Vector Normal(Vector A){
- double L=Length(A);
- if(dcmp(L)==) return Vector(,);
- return Vector(-A.y/L,A.x/L);
- }
- Point p[],b1,b2,st;
- Vector di;
- double s;
- int ti;
- typedef struct Circle{
- Point c;
- double r;
- }Circle;
- Circle cen;
- int getLCI(Point p0,Vector v,double &t1,double &t2){
- double a=v.x; double b=p0.x-cen.c.x;
- double c=v.y; double d=p0.y-cen.c.y;
- double e=a*a+c*c; double f=*(a*b+c*d); double g=b*b+d*d-cen.r*cen.r;
- double delta=f*f-*e*g;
- if(dcmp(delta)<) return ;
- if(dcmp(delta)==){
- t1=t2=-f/(*e);
- return ;
- }
- t1=(-f-sqrt(delta))/(*e);
- t2=(-f+sqrt(delta))/(*e);
- return ;
- }
- bool OnSegment(Point p0,Point a1,Point a2){
- return (dcmp(Cross(a1-p0,a2-p0))== && dcmp(Dot(a1-p0,a2-p0))<);
- }
- bool isPar(Point a1,Point a2){
- Vector v=a2-a1;
- v=v/Length(v);
- if(v==di || (v*-)==di) return ;
- return ;
- }
- Point GLI(Point P,Vector v,Point Q,Vector w){
- Vector u=P-Q;
- double t=Cross(w,u)/Cross(v,w);
- return P+v*t;
- }
- bool isOnLine(Point e){
- Vector u=e-st;
- u=u/Length(u);
- if(u==di) return ;
- return ;
- }
- int solve(){
- int ans=ti;
- double t1,t2;
- Point tt;
- Vector sv,ndi,normal;
- bool f;
- while(ans>){
- if(getLCI(st,di,t1,t2)>){
- if(t1>= || t2>=) return ans;
- }
- f=;
- for(int i=;i<;i++){
- if(isOnLine(p[i])){
- st=p[i]; di=di*-;
- ans-=; f=;
- break;
- }
- }
- if(f) continue;
- for(int i=;i<;i++){
- if(OnSegment(st,p[i],p[(i+)%])) continue;
- if(isPar(p[i],p[(i+)%])) continue;
- sv=p[(i+)%]-p[i];
- tt=GLI(st,di,p[i],sv);
- if(isOnLine(tt) && OnSegment(tt,p[i],p[(i+)%])){
- st=tt;
- normal=Normal(sv);
- ndi=di+normal**fabs(Dot(di,normal));
- di=ndi;
- di=di/Length(di);
- ans--;
- break;
- }
- }
- }
- return ;
- }
- int main()
- {
- int t,ans;
- Vector e;
- //freopen("data.txt","r",stdin);
- scanf("%d",&t);
- for(int z=;z<=t;z++){
- scanf("%lf %lf %lf %lf %lf %lf %d",&s,&b1.x,&b1.y,&b2.x,&b2.y,&cen.r,&ti);
- di=b2-b1;
- di=di/Length(di);
- st=b1;
- cen.c.x=cen.c.y=;
- p[].x=-s; p[].y=;
- p[].x=-s/; p[].y=-s*sqrt3/;
- p[].x=s/; p[].y=-s*sqrt3/;
- p[].x=s; p[].y=;
- p[].x=s/; p[].y=s*sqrt3/;
- p[].x=-s/; p[].y=s*sqrt3/;
- // for(int i=1;i<6;i++){
- // p[i]=Rotate(p[i-1],der60);
- // }
- ans=solve();
- printf("Case %d: ",z);
- if(ans) printf("%d\n",ans);
- else printf("Stops\n");
- }
- return ;
- }
/*12617*/
UVa - 12617 - How Lader的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
随机推荐
- P3990 [SHOI2013]超级跳马
传送门 首先不难设\(f[i][j]\)表示跳到\((i,j)\)的方案数,那么不难得到如下转移 \[f[i][j]=\sum\limits_{k=1}^{\frac n2}f[i-2k+1][j-1 ...
- zabbix详细介绍及其自动动态发现
zabbix3.2.1 第1章 安装 1.1 查看系统环境 [root@centos7-2 ~]# [root@centos7-2 ~]# hostname -I 10.0.0.10 172.16.1 ...
- jquery 菜单展开与收缩参考脚本
/* * metismenu - v1.1.3 * Easy menu jQuery plugin for Twitter Bootstrap 3 * https://github.com/onoku ...
- python tkinter窗口置顶
下面两句即可实现root窗口的置顶显示,可以用于某些程序的消息提示,能够弹出到桌面显示 root = Tk()root.wm_attributes('-topmost',1)
- 231 Power of Two 2的幂
给定一个整数,写一个函数来判断它是否是2的幂. 详见:https://leetcode.com/problems/power-of-two/description/ Java实现: class Sol ...
- Storm概念学习系列之storm的定时任务
不多说,直接上干货! 至于为什么,有storm的定时任务.这个很简单.但是,这个在工作中非常重要! 假设有如下的业务场景 这个spoult源源不断地发送数据,boilt呢会进行处理.然后呢,处理后的结 ...
- Java提要
一.四种权限修饰符 1.访问控制修饰符 作用: 用于控制被修饰变量.方法.类的可见范围. public 的访问级别是最高的,其次是 protected.默认和 private. 成员变量和成员方法可以 ...
- 逻辑回归(Logistic Regression)推导
出自BYRans博客:http://www.cnblogs.com/BYRans/ 本文主要讲解分类问题中的逻辑回归.逻辑回归是一个二分类问题. 二分类问题 二分类问题是指预测的y值只有两个取值(0或 ...
- C/C++ struct定义、声明、对齐方式
一.定义/声明方式 第一种:仅有结构体名,不定义/声明变量 struct MyStruct { int i: char a[10]; double b; }:第二种:有结构体名,并声 ...
- 已集成 VirtIO驱动windows server 2012, 2008, 2003的ISO镜像下载
已集成 VirtIO驱动简体中文windows server 2012, 2008, 2003系统ISO镜像下载地址. 适用于上传自定义ISO并且使用 VirtIO驱动的kvm架构vps,vultr家 ...