[2016.7 test.5] T1
来源:互联网 发布:mac电脑兼容双系统吗 编辑:程序博客网 时间:2024/05/11 02:59
A
时间 1s
描述
给一个 W*H 的矩形,两个小球分别以 (1 , 1) 的方向在 (x1,y1) (x2,y2) 点开始运动,碰到
墙壁依照镜面反射。问是否能相遇如果相遇输出第一个相遇地点。
输入
六个数字代表 W,H,x1,y1,x2,y2
输出
一行 2 个浮点数(保留一位小数),空格隔开,表示第一次相遇的位置。
如果不相遇输出”No”不包括引号
样例
Input
10 10 1 1 9 9
Output
6.0 6.0
30%数据满足 W,H<=100
50%数据满足 W,H<=1000
100%数据满足 W,H<=10000
#include <iostream>#include <iomanip>#include <fstream>#include <stdlib.h>#include <time.h>#include<cstring>#include<cstdio>#include<vector>#include<string>#include<algorithm>#include <limits.h>#include<cmath>#include<map>#include<queue>#include<set>using namespace std;#define LL long long#define eps 1e-10const long long mod =1000000007; //这个必须是质数LL P,Q,a,x,b,y;int dcmp(double d){ return d < -eps ? -1 : d > eps;}LL extend_gcd(LL a,LL b,LL &x,LL &y){ if(b==0) { x=1;y=0;return a; } LL ans=extend_gcd(b,a%b,x,y); LL tmp=x; x=y; y=tmp-(a/b)*y; return ans;}int main(){ freopen("A.in","r",stdin); freopen("A.out","w",stdout); int T=1; int tt=T; while (T--){ scanf("%I64d%I64d%I64d%I64d%I64d%I64d",&P,&Q,&a,&x,&b,&y); if (a==b && x==y) { printf("%.1f %.1f\n",(double)a,(double)x);continue; } if (a==b){ double t = Q - 1. * (x + y) / 2.; double ans = a + t; ans = fmod(ans , 2. * P); if ((ans - P) >= 0) ans = 2. * P - ans; printf("%.1f " , ans); ans = y + t; ans = fmod(ans , 2. * Q); if ((ans - Q) >= 0) ans = 2. * Q- ans; printf("%.1f\n" , ans); continue; } if (x==y){ double t = P - 1. * (a + b) / 2.; double ans = a + t; ans = fmod(ans , 2. * P); if ((ans - P) >= 0) ans = 2. * P - ans; printf("%.1f " , ans); ans = y + t; ans = fmod(ans , 2. * Q); if ((ans - Q) >= 0) ans = 2. * Q - ans; printf("%.1f\n" , ans); continue; } if (abs(a+b-x-y)%2==1 ) { printf("No\n");continue; } LL g=(P-Q)-((a+b-x-y)/2); LL x1,y1; LL gcd=extend_gcd(P,Q,x1,y1); if (g%gcd!=0) { printf("No\n");continue; } x1*=g/gcd; y1*=g/gcd; if (x1>=0){ LL ha=Q/gcd; LL hi=P/gcd; LL f=x1/ha+1; x1-=f*ha;y1+=f*hi; if (x1+ha==0) {x1+=ha;y1-=hi;} }else { LL ha=Q/gcd; LL hi=P/gcd; LL f=-x1/ha; x1-=f*ha;y1+=f*hi; } x1=-x1; double t=P-(a+b)/2.0+x1*P; double ansx,ansy; if (t-(LL)t!=0.5) { a+=(LL)t;a%=(2*P);if (a>P) a=2*P-a;ansx=a; x+=(LL)t;x%=(2*Q);if (x>Q) x=2*Q-x;ansy=x; }else { a+=(LL)t;a%=(2*P);ansx=a+0.5;if (ansx>P) ansx=2*P-ansx; x+=(LL)t;x%=(2*Q);ansy=x+0.5;if (ansy>Q) ansy=2*Q-ansy; } printf("%.1f %.1f\n",ansx,ansy); } return 0;}
1 0
- [2016.7 test.5] T1
- [Loi57 test 2017.4.22]T1字符串
- T1
- T1
- t1
- t1
- t1
- t1
- t1
- T1
- T1
- [2016.7.Test1] T1 三进制异或
- 2016.7.15_模拟赛t1 立方体
- 济南学习 Day 5 T1 am
- 济南学习 Day 5 T1 晚
- 济南学习 Day 5 T1 pm
- 5月30日集训T1
- 2017年10月5提高组T1 密码
- python学习——单元测试
- Android之EventBus
- linux 下文件的批量复制
- Rufus 2.11超级精简版/超精简/懂你版
- [Array] Pascal's Triangle
- [2016.7 test.5] T1
- spark 常用命令
- NYOJ小明的调查作业
- Java File类,IO流,字节输入流InputStream,FileInputStream学习使用
- webuploader 常用设置
- TTEFS 文档密级标识安全管理控件
- python学习——文档测试
- 同步发电机 有功功率 无功功率调节
- [SCU 4532] interesting (数论+技巧+SPFA转移DP)