CF#328 (Div. 2) C(大数)
1 second
256 megabytes
standard input
standard output
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.

Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform onlysteps of length equal to w meters, and Bolt can perform only steps of length equal to bmeters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?
The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Print the answer to the problem as an irreducible fraction
. Follow the format of the samples output.
The fraction
(p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.
10 3 2
3/10
7 1 2
3/7
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
题目看了半天啊!!!看懂了算法很好想,可是要用到大数,电脑没装eclipse,gvim写java也是醉醉的,还好最后过的还不算晚。贴一下代码留着以后参考,后面还要仔细整理下BigInteger,BigDecimal
/*
ID: LinKArftc
PROG: Main.java
LANG: JAVA
*/
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
BigInteger t, w, b;
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
t = input.nextBigInteger();
w = input.nextBigInteger();
b = input.nextBigInteger();
BigInteger mi = w.min(b);
BigInteger gcd = w.gcd(b);
BigInteger lcm = w.multiply(b).divide(gcd);
BigInteger ans, cnt, res;
if (lcm.compareTo(t) > 0) {
ans = t.min(w.subtract(BigInteger.ONE).min(b.subtract(BigInteger.ONE)));
} else {
cnt = t.divide(lcm);
res = t.subtract(cnt.multiply(lcm));
ans = cnt.multiply(w.min(b)).add(res.min((w.subtract(BigInteger.ONE)).min(b.subtract(BigInteger.ONE))));
}
gcd = ans.gcd(t);
System.out.println(ans.divide(gcd)+"/"+t.divide(gcd)); }
}
}
再贴一发Python3代码
import sys
import fractions
for line in sys.stdin:
li = line.split()
t = int(li[0])
w = int(li[1])
b = int(li[2])
mi = min(w, b)
Gcd = fractions.gcd(w, b)
Lcm = w * b // Gcd
if Lcm > t:
ans = min(t, w - 1, b - 1)
else:
cnt = t // Lcm
res = t - cnt * Lcm
ans = cnt * min(w, b) + min(res, w - 1, b - 1)
Gcd = fractions.gcd(ans, t)
print("%s/%s" % (ans // Gcd, t // Gcd))
CF#328 (Div. 2) C(大数)的更多相关文章
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
- CF #374 (Div. 2) D. 贪心,优先队列或set
1.CF #374 (Div. 2) D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...
- CF #374 (Div. 2) C. Journey dp
1.CF #374 (Div. 2) C. Journey 2.总结:好题,这一道题,WA,MLE,TLE,RE,各种姿势都来了一遍.. 3.题意:有向无环图,找出第1个点到第n个点的一条路径 ...
- CF #371 (Div. 2) C、map标记
1.CF #371 (Div. 2) C. Sonya and Queries map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组
题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)
转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...
- CF#138 div 1 A. Bracket Sequence
[#138 div 1 A. Bracket Sequence] [原题] A. Bracket Sequence time limit per test 2 seconds memory limit ...
- Codeforces Round #328 (Div. 2)
这场CF,准备充足,回寝室洗了澡,睡了一觉,可结果... 水 A - PawnChess 第一次忘记判断相等时A先走算A赢,hack掉.后来才知道自己的代码写错了(摔 for (int i=1; ...
随机推荐
- 阿里云SLB上http强制跳转到https问题处理
背景: 最近一客户有一个需求,需要将外网所有http访问请求强制跳转到https,公网出口使用阿里云SLB,证书放在SLB上,SLB后端实例为ECS(webserver)web服务使用nginx, 网 ...
- AcCoder Contest-115 D - Christmas
D - Christmas Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement In some ...
- Windows Server 2008 R2 WEB 服务器安全设置指南
http://wenku.baidu.com/view/9b66c51449649b6649d747a2.html?from=search http://wenku.baidu.com/view/84 ...
- Chrome 与 Firefox-Dev 的 DevTools
不管是做爬虫还是写 Web App,Chrome 和 Firefox 的 DevTools 都是超常用的,但是经常发现别人的截图有什么字段我找不到,别人的什么功能我的 Chrome 没有,仔细一搜索才 ...
- 搞ACM的伤不起
劳资六年前开始搞ACM啊!!!!!!!!!! 从此踏上了尼玛不归路啊!!!!!!!!!!!! 谁特么跟劳资讲算法是程序设计的核心啊!!!!!! 尼玛除了面试题就没见过用算法的地方啊!!!!!! ...
- PokeCats开发者日志(五)
现在是PokeCats游戏开发的第八天的上午,来记录一下将PokeCats上传到360移动开放平台的过程. 首先点创建游戏. 会弹出这个东东. 个人只能创建免费游戏啊,TAT.算了,反 ...
- 【EasyNetQ】- 使用Future Publish调度事件
许多业务流程要求在将来某个日期安排事件.例如,在与客户进行初次销售联系后,我们可能希望在将来的某个时间安排跟进电话.EasyNetQ可以通过其Future Publish功能帮助您实现此功能.例如,这 ...
- html框架集 target
- TCP/IP Note3
TCP/IP协议 TCP/IP是不同的通信协议的大集合. 协议族:TCP/IP是基于TCP和IP这两个最初的协议之上的不同的通信协议的大集合. 1. TCP - 传输控制协议 TCP用于从应用程序到网 ...
- hihocoder 1457(后缀自动机+拓扑排序)
题意 给定若干组由数字构成的字符串,求所有不重复子串的和(把他们看成十进制),答案mod(1e9+7) 题解: 类似后缀数组的做法,把字符串之间用':'连接,这里用':'是因为':'的ascii码恰好 ...