ZOJ 3593 One Person Game】的更多相关文章

One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations…
思路:题意转化为求 (ax+by=dis) || (ax+cy=dis) || (bx+cy=dis) 三个式子有解时的最小|x| + |y|.显然求解特解x,y直接用扩展欧几里得,那么怎么求|x| + |y|?xy关系为一条直线,那么|x| + |y|应该是在x取0或者y取0的时候,但是要整数,所以只能在周围取几个点.我们知道x=x1+b/gcd*t,那么x1+b/gcd*t = 0可以解得 t  = -x1 * gcd / b.然后在附近取几个点. 代码: #include<iostream…
One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is point B. There are 6 kinds of operations…
题意:一个人在坐标A,要前往坐标B的位置.可以往左或往右走a,b,a+b个单位,求到达B的最小步数. 分析:扩展欧几里得算法求解线性方程的套路不变.令C=fabs(A-B),c = a+b, 扩展gcd分别求 ax+by=C ; ax+cy = C : bx+cy = C的最小|x|+|y|.求min{|x|+|y|}需要一点思考. 对于线性方程ax+by=c,设d = gcd(a,b) ,若方程有解,则必须d | c,特解为 (x0,y0) = ( xx*c/d,yy*c/d) .设am =…
智障了,智障了,水一水博客. 本来是个水题,但是for循环遍历那里写挫了... One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at first and your aim is…
题意:一个人要从A走到B  只能走a布.b步.(a+b)步,可以往左或右走   问 最少要走几步,不能走到的输出-1 可以列出方程 $ax+by=A-B$ 或者 $ax+(a+b)y=A-B$ 或者 $bx+(a+b)y=A-B$ 要取这三个方程的最小的$(x+y)$ 根据$ax+by=gcd(a, b) $ 当$A-B$不是$gcd$的倍数时 就不能走到 利用ex_gcd可以分别求出这三个方程的解,但求出的这组并非最小的 因此利用枚举斜率 得到的交点为最小的一组解 LL exgcd(LL a,…
One Person Game Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3593 Description There is an interesting and simple one person game. Suppose there is a number axis under your feet. You are at point A at f…
ZOJ Problem Set - 3593 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3593 One Person Game Time Limit: 2 Seconds      Memory Limit: 65536 KB There is an interesting and simple one person game. Suppose there is a number axis under your f…
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3944 In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitre…
A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the labels are 0. We define this kind of operation: given a subtree, negate all its labels. An…