版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chenzhenyu123456/article/details/62428002
这里记录三道水题~~~
发现
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 3e6 + 1;
const int MOD = 1e9 + 7;
typedef long long LL;
void add(LL &x, LL y) { x += y; x %= MOD; }
typedef pair<double, double> pii;
int f[30];
int main()
{
// fn = 1/sqrt(5) * (((1 + sqrt(5)) / 2) ^ n - (1 - sqrt(5)) / 2) ^ n)
double a = (1 + sqrt(5)) / 2;
double b = (1 - sqrt(5)) / 2;
double c = 1.0 / sqrt(5);
// printf("%lf %lf %lf\n", a, b, c);
f[0] = 0, f[1] = 1;
for(int i = 2; i <= 21; i++) {
f[i] = f[i - 1] + f[i - 2];
}
// cout << f[21] << endl;
// printf("%.6lf\n", pow(b, 21));
int n;
while(scanf("%d", &n) != EOF) {
if(n <= 20) {
printf("%d\n", f[n]);
continue;
}
double T = log10(c) + n * log10(a);
// printf("%lf\n", T);
double X = T - (LL)T;
printf("%d\n", (int)(pow(10, X) * 1000));
}
return 0;
}
不同数相加异或完之后就没了。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int MAXN = 5e5 + 1;
const int MOD = 1e9 + 7;
typedef long long LL;
void add(LL &x, LL y) { x += y; x %= MOD; }
typedef pair<double, double> pii;
int main()
{
int t; scanf("%d", &t);
while(t--) {
int n, m, z, l;
scanf("%d%d%d%d", &n, &m, &z, &l);
LL a = 0; LL ans = 0;
for(int i = 2; i <= n; i++) {
a = (a * m + z) % l;
ans ^= (a * 2);
}
printf("%lld\n", ans);
}
return 0;
}
模拟二叉树,小左大右。阅读理解题~~~
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int MAXN = 2e3 + 1;
const int MOD = 1e9 + 7;
typedef long long LL;
void add(LL &x, LL y) { x += y; x %= MOD; }
typedef pair<double, double> pii;
int Next[MAXN][2], val[MAXN], L, root;
int newnode() {
Next[L][0] = Next[L][1] = -1;
val[L++] = 0;
return L - 1;
}
void Init() { L = 0; root = newnode(); }
void Insert(int x, int u) {
if(x < val[u]) {
if(Next[u][0] == -1) {
Next[u][0] = newnode();
val[Next[u][0]] = x;
return;
}
Insert(x, Next[u][0]);
}
else {
if(Next[u][1] == -1) {
Next[u][1] = newnode();
val[Next[u][1]] = x;
return;
}
Insert(x, Next[u][1]);
}
}
void Work(int x, int u) {
if(val[u] == x) {
return;
}
else if(x < val[u]) {
printf("E");
Work(x, Next[u][0]);
}
else {
printf("W");
Work(x, Next[u][1]);
}
}
int main()
{
int t; scanf("%d", &t);
while(t--) {
int n; scanf("%d", &n); Init();
for(int i = 1; i <= n; i++) {
int a; scanf("%d", &a);
if(i == 1) {
val[root] = a;
}
else {
Insert(a, root);
}
}
int q; scanf("%d", &q);
while(q--) {
int x; scanf("%d", &x);
if(val[root] != x) {
Work(x, root);
}
printf("\n");
}
}
return 0;
}