T1
找规律发现点
a
的父亲是
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 101
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drp(i, a, b) for (int i = a; i >= b; i--)
#define fech(i, x) for (int i = 0; i < x.size(); i++)
#define ll long long
#define abs(x) ((x) < 0 ? -(x) : (x))
inline ll read() {
ll x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
inline void write(ll x) { if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }
const ll fib[] = { 0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946,
17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465,
14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903,
2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445,
225851433717, 365435296162, 591286729879, 956722026041, 1548008755920};
int find(ll x) {
int l = 1, r = 59, ans;
while (l <= r) {
int mid = l + r >> 1;
if (fib[mid] < x) ans = mid, l = mid + 1;
else r = mid - 1;
}
return ans;
}
int main() {
int m = read();
while (m--) {
ll a = read(), b = read();
if (a == b) { printf("%lld\n", a); continue; }
if (abs(a - b) <= 1) { puts("1"); continue; }
if (a == 1 || b == 1) { puts("1"); continue; }
while (a != b) {
if (a < b) swap(a, b);
a -= fib[find(a)];
}
write(a), puts("");
}
return 0;
}
T2
代码解释一切系列。
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 300001
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drp(i, a, b) for (int i = a; i >= b; i--)
#define fech(i, x) for (int i = 0; i < x.size(); i++)
#define ll long long
inline int read() {
int x = 0, flag = 1; char ch = getchar();
while (ch > '9' || ch < '0') { if (ch == '-') flag = -1; ch = getchar(); }
while (ch <= '9' && ch >= '0') { x = x * 10 + ch - '0'; ch = getchar(); }
return x * flag;
}
inline void write(int x) { if (x >= 10) write(x / 10); putchar(x % 10 + '0'); }
int n;
int a[N];
vector<int> bur[N];
int main() {
cin >> n; int m = read();
rep(i, 1, n) a[i] = read(), bur[a[i]].push_back(i);
while (m--) {
int op = read();
if (op == 1) {
int l = read(), r = read(), c = read();
write((int)(upper_bound(bur[c].begin(), bur[c].end(), r) - lower_bound(bur[c].begin(), bur[c].end(), l)));
puts("");
}
else {
int x = read();
if (a[x] == a[x + 1]) continue;
(*lower_bound(bur[a[x]].begin(), bur[a[x]].end(), x))++;
(*lower_bound(bur[a[x + 1]].begin(), bur[a[x + 1]].end(), x + 1))--;
swap(a[x], a[x + 1]);
}
}
return 0;
}
T3
但口胡,调不出来啊。调好了再写。