A. 门牌制作

答案

624

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int cnt = 0;
for (int i = 1; i <= 2020; i++) {
int x = i;
while (x) {
if (x % 10 == 2) ++cnt;
x /= 10;
}
}
cout << cnt << "\n";
return 0;
}

B. 既约分数

答案

2481215

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int cnt = 0;
for (int i = 1; i <= 2020; i++) {
for (int j = 1; j <= 2020; j++) {
if (__gcd(i, j) == 1)
++cnt;
}
}
cout << cnt << "\n";
return 0;
}

C. 蛇形填数

答案

761

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int x = 1, y = 1;
int a[100][100] = {};
int num = 1;
for (int i = 1; x <= 50; i++) {
for (int j = 0; j < i; j++) {
a[x][y] = num++;
if (j != i - 1) {
if (i & 1) --x, ++y;
else ++x, --y;
}
}
if (i & 1) ++y;
else ++x;
}
cout << a[20][20] << "\n";
return 0;
}

D. 七段码

答案

80

代码

#include <bits/stdc++.h>
using namespace std; bool light[7];
vector<vector<int> > G(7);
int ans; bool judge(vector<int> &v1) {
vector<int> v2;
queue<int> que;
bool vis[7] = {};
que.push(v1[0]);
vis[v1[0]] = true;
while (!que.empty()) {
int u = que.front();
que.pop();
v2.push_back(u);
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (find(v1.begin(), v1.end(), v) != v1.end() && !vis[v]) {
que.push(v);
vis[v] = true;
}
}
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
return v2 == v1;
} void dfs(int dep) {
if (dep == 7) {
vector<int> v;
for (int i = 0; i < 7; i++) if (light[i]) v.push_back(i);
if (v.size() && judge(v)) ++ans;
return;
}
light[dep] = true;
dfs(dep + 1);
light[dep] = false;
dfs(dep + 1);
} void build_graph() {
G[0].push_back(1), G[0].push_back(5);
G[1].push_back(0), G[1].push_back(2), G[1].push_back(6);
G[2].push_back(1), G[2].push_back(3), G[2].push_back(6);
G[3].push_back(2), G[3].push_back(4);
G[4].push_back(3), G[4].push_back(5), G[4].push_back(6);
G[5].push_back(0), G[5].push_back(4), G[5].push_back(6);
G[6].push_back(1), G[6].push_back(2), G[6].push_back(4), G[6].push_back(5);
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
build_graph();
dfs(0);
cout << ans << "\n";
return 0;
}

E. 平面分割

答案

1391

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int line[25] = {};
line[1] = 2;
for (int i = 2; i <= 20; i++) {
line[i] = line[i - 1] + i;
}
int ans = line[20];
for (int i = 1; i <= 20; i++) {
ans += 40 + 2 * (i - 1);
}
cout << ans << "\n";
return 0;
}

F. 成绩分析

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
scanf("%d", &n);
int mx = -1, mi = 101, sum = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
mx = max(mx, x);
mi = min(mi, x);
sum += x;
}
printf("%d\n", mx);
printf("%d\n", mi);
printf("%.2f\n", 1.0 * sum / n);
return 0;
}

G. 回文日期

代码

#include <bits/stdc++.h>
using namespace std;
const int month[2][13] = {
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
string my_to_string(int n) {
string s;
do {
s += '0' + n % 10;
n /= 10;
} while (n);
reverse(s.begin(), s.end());
return s;
}
int my_stoi(const string &s) {
int res = 0;
for (int i = 0; i < int(s.size()); i++) {
res = res * 10 + s[i] - '0';
}
return res;
}
bool is(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
bool legal(const string &s) {
int y = my_stoi(s.substr(0, 4));
int m = my_stoi(s.substr(4, 2));
int d = my_stoi(s.substr(6, 2));
if (m < 1 || m > 12) return false;
if (d < 1 || d > month[is(y)][m]) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> v1, v2;
for (int i = 1000; i <= 9999; i++) {
string s1(my_to_string(i));
string s2(s1.rbegin(), s1.rend());
string s = s1 + s2;
string t(s.rbegin(), s.rend());
if (legal(s)) {
if (s == t) {
v1.push_back(my_stoi(s));
}
if ((s[0] == s[2] && s[2] == s[5] && s[5] == s[7]) &&
(s[1] == s[3] && s[3] == s[4] && s[4] == s[6]) &&
(s[0] != s[1])) {
v2.push_back(my_stoi(s));
}
}
}
int n;
cin >> n;
cout << *upper_bound(v1.begin(), v1.end(), n) << "\n";
cout << *upper_bound(v2.begin(), v2.end(), n) << "\n";
return 0;
}

H. 子串分值

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
vector<vector<int> > pos(26);
for (int i = 0; i < 26; i++) {
pos[i].push_back(-1);
}
for (int i = 0; i < n; i++) {
pos[s[i] - 'a'].push_back(i);
}
for (int i = 0; i < 26; i++) {
pos[i].push_back(n);
}
long long ans = 0;
for (int i = 0; i < 26; i++) {
for (int j = 1; j + 1 < int(pos[i].size()); j++) {
int l = pos[i][j] - pos[i][j - 1] - 1;
int r = pos[i][j + 1] - pos[i][j] - 1;
ans += 1LL * (l + 1) * (r + 1);
}
}
cout << ans << "\n";
return 0;
}

最新文章

  1. 去IOE的一点反对意见以及其他
  2. 海外建VPS并支持VPN
  3. Python~删除空格,插入换行符号
  4. js之oop &lt;六&gt;数组的crud(增删改)
  5. JavaScript数据类型
  6. Swagger .Net配置
  7. MySQLdb操作mysql的blob值
  8. 实现在Android 进程和线程
  9. treeview递归加载
  10. Mac快捷键、命令行
  11. 讓 MySQL 能夠用 EF6
  12. 为什么 var_dump(&quot;1&quot; == &quot;1e0&quot;); 的结果为true
  13. iOS推送介绍
  14. jQuery(1)——了解jQuery
  15. sql server中的分页数据查询
  16. How to create and start VirtualBox VM without GUI
  17. Linux基础学习笔记2-文件管理和重定向
  18. 【 js 工具 】如何使用Git上传本地项目到github?(mac版)
  19. 利用scp 远程上传下载文件/文件夹
  20. Python 之 Difflib

热门文章

  1. spring boot 邮件服务
  2. tp where使用数组条件,如何设置or,and
  3. 代码审计 - BugkuCTF
  4. D2Admin 登录用户重新初始话右侧菜单
  5. 用 UniRx 实现 Timeline 式的异步操作
  6. ts类与修饰符
  7. 使用axis1.4生成webservice的客户端代码
  8. django ajax应用
  9. JS复习笔记一:冒泡排序和二叉树列
  10. SELECT ... FOR UPDATE or SELECT ... FOR SHARE Locking Reads session