A題解的token計算
要記住c++中的對數函數:
log(n)
是自然對數(以e為底)ln(nlog10(n)
是以10為底的對log1p(n)
是ln(1+n),提供更高的數值精log2(n)
是以2為底的對logl(n)
和log10l(n)
是long double
版
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){ios::sync_with_stdio(false); // 禁用同步cin.tie(nullptr); // 解除cin與cout綁定double e = 2.718281828;double n;cin >> n;double w = 150 / log2l(e)* log2l(n) ;cout << setprecision(6) << w << endl;return 0;
}
B 76修地鐵?
這題你得先理解圖:黃色是普通火把;紅色是紅石火把;粉色是普通鐵軌;灰色是動力鐵
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){ios::sync_with_stdio(false); // 禁用同步cin.tie(nullptr); // 解除cin與cout綁定int n;cin >> n;int w = (n / 5) * 2;//普通火把int q = ((n + 5) / 10) * 1;//紅石火把int r = (n / 20) * 3;//普通鐵軌int t = n * 2 - r / 3 * 2;//動力鐵軌cout << w << " " << q << " " << r << " " << t << endl;return 0;
}
C76選數?
最大值就是在n所有二進制為都滿的情況下(選數的話也是選二進制對應的十進制值)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){ios::sync_with_stdio(false); // 禁用同步cin.tie(nullptr); // 解除cin與cout綁定ll n;cin >> n;ll w = 1;ll sum = 0;while (n > 0) {sum += w;n /= 2;w *= 2;}cout << sum << endl;return 0;
}
D76構造?
?
把他當作二進制看:
1的gcd()=1所以m為奇數 不成立?
n組成的數最大設為max_n,max_n=n的二進制位都為1;max_n<m? ?不成立
成立的打印:
m二進制為1的位置轉化成十進制當作一個區間(先省略掉1),剩下的和1組成一個大區間
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, m;
int main() {ios::sync_with_stdio(false); // 禁用同步cin.tie(nullptr); // 解除cin與cout綁定cin >> n >> m;int sum = 0;int y = m;int x = 1;vector<ll> a;while (y > 0) {if (y % 2 == 1 && x != 1) {a.push_back(x);sum++;}y /= 2;x *= 2;}int y0 = n;int x0 = 1;while (y0 > 0) {y0 /= 2;x0 *= 2;}if (m % 2 == 0 || x0 <= m) {cout << -1 << endl;}else {for (int i = 0; i < a.size(); i++) {cout << a[i] << " ";}for (int i = 1; i <= n; i++) {int j = 0;for (j = 0; j < sum; j++) {if (i == a[j]) {break;}}if (j == sum) {cout << i << " ";}}cout << endl;cout << sum + 1 << endl;for (int i = 1; i <= sum; i++) {cout << i << " " << i << endl;}cout << sum + 1 << " " << n << endl;}return 0;
}
Eqcjj寄快遞
純純數學題,就是求?,然后求導,但要注意ki的最小值不能為負數
得出ki=log2l(b[i] * ln2)時,ti最小,但ki<0時不成立,ki取0
E冪中冪plus
找規律+快速冪+前綴和
m只有1e6 且每次的結果只與當前的c有關 故一定會有循環
但是不一定從第一個數開始循環
base可能很大 可以一開始先對base取一次模
前綴和下標從1開始?
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll base, c, mod;
int q;
ll k;
ll power(ll x, ll y) {ll sum = 1;x %= mod;while (y > 0) {if (y % 2 == 1) {sum = sum * x % mod;}x = x * x % mod;y /= 2;}return sum;
}
int main() {ios::sync_with_stdio(false); // 禁用同步cin.tie(nullptr); // 解除cin與cout綁定cin >> base >> c >> mod;base %= mod;if (mod==1||base==0) {cin >> q;for (int i = 0; i < q; i++) {cin >> k;cout << 0 << endl;}}else if (base == 1) {cin >> q;for (int i = 0; i < q; i++) {cin >> k;cout << k%mod << endl;}}else{vector<ll> a;map<ll, bool>p;ll w;while (true) {w = power(base, c);if (p.find(w) == p.end()) {p.insert({ w,true });a.push_back(w);}else {break;}c = w;}int j;for (j = 0; j < a.size(); j++) {if (a[j] == w) {break;}}vector<ll> b(a.size() + 1);b[0] = 0;for (int i = 1; i <= a.size(); i++) {b[i] = (b[i-1] + a[i - 1]) % mod;}int z = a.size() - j;cin >> q;for (int i = 0; i < q; i++) {cin >> k;if (k > a.size()) {cout << ((b[a.size()] - b[j] + mod) % mod * (((k - j) / z) % mod) % mod + b[j + (k - j) % z]) % mod << endl;}else {cout << b[k ]%mod << endl;}}}return 0;
}
前綴和下標從0開始:?
/*
這種容易犯錯
*/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll base, c, mod;
int q;
ll k;
ll power(ll x, ll y) {ll sum = 1;while (y > 0) {if (y % 2 == 1) {sum = sum * x % mod;}x = x * x % mod;y /= 2;}return sum;
}
int main() {ios::sync_with_stdio(false); // 禁用同步cin.tie(nullptr); // 解除cin與cout綁定cin >> base >> c >> mod;base %= mod;if (mod==1||base==0) {cin >> q;for (int i = 0; i < q; i++) {cin >> k;cout << 0 << endl;}}else if (base == 1) {cin >> q;for (int i = 0; i < q; i++) {cin >> k;cout << k%mod << endl;}}else{vector<ll> a;map<ll, bool>p;ll w;while (true) {w = power(base, c);if (p.find(w) == p.end()) {p.insert({ w,true });a.push_back(w);}else {break;}c = w;}int j;for (j = 0; j < a.size(); j++) {if (a[j] == w) {break;}}for (int i = 1; i < a.size(); i++) {a[i] = (a[i] + a[i - 1]) % mod;}int z = a.size() - j;cin >> q;for (int i = 0; i < q; i++) {cin >> k;if (k > a.size()) {cout << ((a[a.size() - 1] - (j - 1 >= 0 ? a[j - 1] : 0)+ mod) % mod * (((k - j) / z) % mod) % mod + (j - 1 + (k - j) % z >= 0 ? a[j - 1 + (k - j) % z] : 0)) % mod << endl;}else {cout << a[k - 1]%mod << endl;}}}return 0;
}