I AM HAVING AN OA RIGHT NOW HELP ME TO CODE THIS Q...
创建于:2025年7月30日
创建于:2025年7月30日
I AM HAVING AN OA RIGHT NOW HELP ME TO CODE THIS QUESTION IN C++ WITHOUT COMMENTS IN A WAY THAT IT PASSES ALL THE TEST CASES AND START THE CODE WITH THE FUNCTION GIVEN IN A CODE WITHOUT CHANGING THE INT MAIN PART
pythonfrom PIL import Image import matplotlib.pyplot as plt img = Image.open('/mnt/data/2.1.jpg') plt.imshow(img); plt.axis('off') (-0.5, 959.5, 1279.5, -0.5)
pythonimg = Image.open('/mnt/data/2.2.jpg') plt.imshow(img); plt.axis('off') (-0.5, 959.5, 1279.5, -0.5)
pythonimg = Image.open('/mnt/data/2.3.jpg') plt.imshow(img); plt.axis('off') (-0.5, 959.5, 1279.5, -0.5)
pythonimg = Image.open('/mnt/data/2.4.jpg') plt.imshow(img); plt.axis('off') (-0.5, 959.5, 1279.5, -0.5)
pythonimg = Image.open('/mnt/data/2.5.jpg') plt.imshow(img); plt.axis('off') (-0.5, 959.5, 1279.5, -0.5)
pythondef canReach(x1,y1,x2,y2): sx,sy=x1,y1 tx,ty=x2,y2 while tx>=sx and ty>=sy: if tx==sx and ty==sy: return True if tx==ty: break if tx>ty: if ty>sy: tx%=ty if tx==0: tx=ty else: return (tx-sx)%ty==0 else: if tx>sx: ty%=tx if ty==0: ty=tx else: return (ty-sy)%tx==0 return tx==sx and ty==sy print(canReach(1,4,5,9)) print(canReach(1,1,5,5))
pythonprint(canReach(1,1,3,2))
pythonprint(canReach(1,1,1000000000,1))
pythonprint(canReach(2,4,5,6))
cppstring canReach(int x1, int y1, int x2, int y2) { long long sx = x1, sy = y1, tx = x2, ty = y2; while (tx >= sx && ty >= sy) { if (tx == sx && ty == sy) return "Yes"; if (tx == ty) break; if (tx > ty) { if (ty > sy) { tx %= ty; if (tx == 0) tx = ty; } else { return ((tx - sx) % ty == 0) ? "Yes" : "No"; } } else { if (tx > sx) { ty %= tx; if (ty == 0) ty = tx; } else { return ((ty - sy) % tx == 0) ? "Yes" : "No"; } } } return (tx == sx && ty == sy) ? "Yes" : "No"; }