hdoj 1568 && hdoj 5344 && hdoj 5444
来源:互联网 发布:淘宝的阿玛尼这么便宜 编辑:程序博客网 时间:2024/04/28 00:04
这里记录三道水题~~~
Fibonacci
发现
#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;}
MZL’s xor
不同数相加异或完之后就没了。
#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;}
Elven Postman
模拟二叉树,小左大右。阅读理解题~~~
#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;}
0 0
- hdoj 1568 && hdoj 5344 && hdoj 5444
- HDOJ
- hdoj
- hdoj
- HDOJ
- hdoj 5344 找规律
- hdoj 1568 Fibonacci
- hdoj-1568-Fibonacci
- HDOJ-----1568---Fibonacci数学题
- hdoj-【1568 Fibonacci】
- HDOJ 2176
- Hdoj--1272
- hdoj 1003
- hdoj 1005
- hdoj 1030
- hdoj 2154
- hdoj 2100
- HDOJ 1106
- java中的常见异常总结
- three.js之性能检测插件(state)
- angularjs2-----路由
- 在pdf文件中怎样编辑pdf文件图片
- 初步使用scikit-learn
- hdoj 1568 && hdoj 5344 && hdoj 5444
- Why tcp 3,4?
- Nginx配置文件(nginx.conf)配置详解
- python Manager对象增加进程
- view绘制流程介绍
- android studio 集成科大讯飞语音合成以及语音评测
- MySQL5.7.11免安装版的安装和配置以及解决MYSQL服务无法启动问题
- 在线浏览PDF文件
- android 命名规范