当前位置:网站首页>ShanDong Multi-University Training #4 A、B、C、G
ShanDong Multi-University Training #4 A、B、C、G
2022-08-04 12:23:00 【eyuhaobanga】
或运算,1不是题意下的质数,其他
和
均是质数,剩下的不是
AC代码:
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; LL lowbit(LL x) { return x & -x; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); LL n; cin >> n; LL x = n; int cnt = 0; LL y = lowbit(n); while (x) { if (x & 1) { cnt++; } x >>= 1; } if (cnt == 1) { if (n == 1) { cout << "No\n"; } else { cout << "Yes\n"; } } else if (cnt == 2) { if (y == 1) { cout << "Yes\n"; } else { cout << "No\n"; } } else { cout << "No\n"; } return 0; }
可知要得
,可得到
,n是1e5但异或值域只有不到2e5,那么根据鸽巢原理暴力跑即可
AC代码:
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } map<int, int> mp; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (mp[a[i] ^ a[j]] == 1) { cout << "Yes\n"; return 0; } mp[a[i] ^ a[j]] = 1; } } cout << "No\n"; return 0; }
大数取模模拟,因为它我才知道我的大数取模模板的取模运算锅了QAQ
AC代码:
#include <iostream> #include <cstdio> #include <queue> #include <deque> #include <stack> #include <string> #include <cstring> #include <numeric> #include <functional> #include <cstdlib> #include <vector> #include <set> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; //head const LL mod = 1e9 + 7; LL a[200010]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int len = s.size(); s = '*' + s; int q; cin >> q; LL sum = 0; for (int i = 1; i <= len; i++) { sum = a[i - 1]; a[i] = (sum * 10 + (LL)(s[i] - '0')) % mod; } rep (i, 0, q) { string op; cin >> op; int x; if (op == "+") { cin >> x; sum = a[len]; len++; a[len] = (sum * 10 + x) % mod; cout << a[len] << '\n'; } else { len--; cout << a[len] << '\n'; } } return 0; }
数位DP板板题,先找Fibonacci数列的规律,可以猜到的是所有Fibonacci数列里的数都是包含1、2、3、5、8的,那么就有了数位DP的基础,就是不要1、2、3、5、8,统计0到n有多少个这样的数
AC代码:
#include <bits/stdc++.h> #define rep(i,a,n) for(int i=a;i<n;i++) using namespace std; using LL = long long; LL dp[20][20], w[20], cnt = 0; LL getfib(LL x) { if (x == 1) { return 1; } if (x == 0) { return 0; } return getfib(x - 1) + getfib(x - 2); } LL dfs(int x, int p, int flag) {//1 2 3 5 8->p=0or1 if (x < 0) { return p == 0; } if (dp[x][p] != -1 && !flag) { return dp[x][p]; } int lim = flag ? w[x] : 9; LL ans = 0; for (int i = 0; i <= lim; i++) { if (i == 1) { if (p == 0) { ans += dfs(x - 1, 1, flag && (i == lim)); } else { continue; } } else if (i == 2) { if (p == 0) { ans += dfs(x - 1, 1, flag && (i == lim)); } else { continue; } } else if (i == 3) { if (p == 0) { ans += dfs(x - 1, 1, flag && (i == lim)); } else { continue; } } else if (i == 5) { if (p == 0) { ans += dfs(x - 1, 1, flag && (i == lim)); } else { continue; } } else if (i == 8) { if (p == 0) { ans += dfs(x - 1, 1, flag && (i == lim)); } else { continue; } } else { if (p == 0) { ans += dfs(x - 1, 0, flag && (i == lim)); } else { continue; } } } if (!flag) { dp[x][p] = ans; } return ans; } void Solve() { LL n; cin >> n; cnt = 0; while (n) { w[cnt] = n % 10; cnt++; n /= 10; } cnt--; memset(dp, -1, sizeof(dp)); cout << dfs(cnt, 0, 1) << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; // for (int i = 0; i <= T; i++) { // cout << getfib(i) << '\n'; // } rep (i, 0, T) { Solve(); } return 0; }
边栏推荐
- Analysis and comparison of mobile cross-end technical solutions
- 力扣每日一题-第48天-345. 反转字符串中的元音字母
- MySQL - Explain详解
- 划重点!2022面试必刷461道大厂架构面试真题汇总+面经+简历模板
- 外置USB供电与内置锂电池供电自动切换电路
- 两年独立开发经验程序员告诉我们赚钱的经验(听听真正赚到钱的高手做法)
- Matlab记录
- Cool and efficient data visualization big screen, it's really not that difficult to do!丨Geek Planet
- 终于有人把分布式机器学习讲明白了
- 2022上半年各银行理财子公司深耕差异化发展,净值型产品数量增加
猜你喜欢
随机推荐
Nacos手摸手教学【二】Nacos注册中心
移动跨端技术方案分析对比
两年独立开发经验程序员告诉我们赚钱的经验(听听真正赚到钱的高手做法)
COMSOL空气反应 模型框架
Redis(一)安装与配置
UMA & Hong Kong Polytechnic & Ali propose SP-ViT to learn 2D space prior knowledge for visual Transformer!
【UML】信息系统分析与设计知识点总结
Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
终于有人把分布式机器学习讲明白了
Focus!2022 interview must brush 461 interview questions summary + interview + resume template
244页pdf!《2022 中国云计算生态蓝皮书》发布
他是“中台”之父,凭一个概念为阿里狂赚百亿
拥有一台服务器,程序猿装X的开始
活动报名:如何高效应对当下的实时场景需求?
SchedulX V1.5.0发布,提供快速压测、对象存储等全新功能!
200ppi转以太网通过4Gwifi在医药设备移动平台(平板电脑、手机)
UMA&港理工&阿里提出SP-ViT,为视觉Transformer学习2D空间先验知识!
TPC藏宝计划IDO自由协议复利模式开发功能分析
Hands-on Deep Learning_LeNet
接入华为游戏防沉迷,点击防沉迷弹窗后游戏闪退