操作轮数
和辗转相除法的思维很相似,具体细节见代码
#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;
}