AcWing -- 5141. 操作轮数+5142. 移动棋子

操作轮数

和辗转相除法的思维很相似,具体细节见代码

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sf(x) scanf("%d", &x);
#define de(x) cout << x << " ";
#define Pu puts("");
const int N = 1e6 + 9;
ll a, b, ans;
void fun(ll x, ll y) {
    if (x % y == 0) {  // 如果能整除,则直接返回
        ans += (x / y);
        return;
    }
    if (y % x == 0) {
        ans += (y / x);
        return;
    }
    if (x < y) {  // 不能整除时,相当于一直对大的那个做减法
        // 最终大的那个数变为 (大数)%(小数)
        ans += (y / x);
        y %= x;
        fun(x, y);
    } else if (y < x) {
        ans += (x / y);
        x %= y;
        fun(x, y);
    }
}
int main() {
    cin >> a >> b;
    ans = 0;
    fun(a, b);
    cout << ans;
    return 0;
}

移动棋子

注意与棋子位置恰好为r的点不一定是整数!
原本我以为是整数,都准备进行广度优先搜索遍历了,但是
后来发现坐标没有办法进行存储,所以看了题解,,,

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sf(x) scanf("%d", &x);
#define de(x) cout << x << " ";
#define Pu puts("");
const int N = 1e5 + 9;
double r, a, b, c, d;
int main() {
    cin >> r >> a >> b >> c >> d;
    double dis = sqrt((a - c) * (a - c) + (b - d) * (b - d));
    double u = dis / (double)(2 * r);
    // de(d) de(u);
    cout << ceil(u) << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值