Codeforces Round #328 (Div. 2) 592 C. The Big Race
2016-01-26 04:23
344 查看
题意:有两个这什么…
![](http://img.blog.csdn.net/20160126041225405)
他们两个要比赛,他们第一个一步跨w米,第二个一步跨b米
现在有个长为t米的赛道,t米后边全是陷阱
现在让你当裁判,你可以选择1~t米里边任意长度当作终点
然后两个比赛 比赛规则是 走任意步数,但是不能超过终点,可以到达
距离终点最近的获胜
问你有多少的几率使两个人距离终点的米数一样 化为最简分数的形式(注意1/1
思路:
这个一看就知道米数一样只有两种情况
第一种 能让这两个一步都不跨的距离作为终点
第二种
x为w和b的最小公倍数 终点的距离t要满足 t-t/x*x
他们两个要比赛,他们第一个一步跨w米,第二个一步跨b米
现在有个长为t米的赛道,t米后边全是陷阱
现在让你当裁判,你可以选择1~t米里边任意长度当作终点
然后两个比赛 比赛规则是 走任意步数,但是不能超过终点,可以到达
距离终点最近的获胜
问你有多少的几率使两个人距离终点的米数一样 化为最简分数的形式(注意1/1
思路:
这个一看就知道米数一样只有两种情况
第一种 能让这两个一步都不跨的距离作为终点
第二种
x为w和b的最小公倍数 终点的距离t要满足 t-t/x*x
[code]#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<queue> #include<stack> #include<string> #include<vector> #include<map> #include<set> using namespace std; #define rfor(i,a,b) for(i=a;i<=b;++i) #define lfor(i,a,b) for(i=a;i>=b;--i) #define sfor(i,a,h) for(i=h[a];i!=-1;i=e[i].next) #define mem(a,b) memset(a,b,sizeof(a)) #define mec(a,b) memcpy(a,b,sizeof(b)) #define cheak(i) printf("%d ",i) #define min(a,b) (a>b?b:a) #define max(a,b) (a>b?a:b) #define inf 0x3f3f3f3f #define lowbit(x) (x&(-x)) typedef long long LL; #define maxn 100005 #define maxm maxn*maxn #define lson(x) (splay[x].son[0]) #define rson(x) (splay[x].son[1]) LL t; int judge(double a,double b) { a*=b; if(a>t) return 1; return 0; } LL gcd(LL a,LL b) { if(a==0) return b; return gcd(b%a,a); } int main() { LL w,b; scanf("%lld%lld%lld",&t,&w,&b); if(w==b) { printf("1/1\n"); return 0; } LL ans=min(w-1,min(t,b-1)); LL x=gcd(w,b); if(judge(w/x,b)) { LL x=gcd(ans,t); printf("%lld/%lld\n",ans/x,t/x); return 0; } x=(w/x)*b; LL q=t/x; if(q) { ans+=(q-1)*min(w,b); ans+=min(w,min(b,t-q*x+1)); } x=gcd(ans,t); printf("%lld/%lld\n",ans/x,t/x); return 0; }
相关文章推荐
- 关于鸣人发招
- ansible官方文档翻译之变量
- ansible官方文档翻译之变量
- Codeforces Round #328 (Div. 2) 592 B. The Monster and the Squirrel
- Codeforces Round #328 (Div. 2) 592A PawnChess
- Osmocom-BB多信道修改代码相关
- C118 免按开机自动加载固件
- 关于清除浮动
- POJ1651:Multiplication Puzzle(区间DP)
- POJ2955:Brackets(区间DP)
- 前端试题-两列等高布局
- *Check whether a given graph is Bipartite or not
- 小娜学法(17):如何获取案件信息?
- MongoDB Aggregate Methods(2) MonoDB 的 3 种聚合函数
- 输出螺旋矩阵
- 03-构造可靠数据传输协议
- 02-topdown
- U3d键值整理
- MONGODB 与sql聚合操作对应图
- grub 启动错误 "file not found"