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;
}

2020第十一届蓝桥杯第二场省赛C++A组【A-H】的更多相关文章

  1. 2020第十一届蓝桥杯第二场JavaB组

    第一题:门牌制作(624) 题目大意: 判断1到2020里面共有多少个'2': 解析: 本题简而言之就是找'2'这一个数 第一种方法:遍历将其转换为字符然后再遍历寻找 第二种方法:直接用数值的方法进行 ...

  2. Java实现第十一届蓝桥杯JavaB组 省赛真题

    试题 A: 指数计算 本题总分:5 分 [问题描述] 7 月 1 日是建党日,从 1921 年到 2020 年, 已经带领中国人民 走过了 99 年. 请计算:7 ^ 2020 mod 1921,其中 ...

  3. CTF-i春秋网鼎杯第二场misc部分writeup

    CTF-i春秋网鼎杯第二场misc部分writeup 套娃 下载下来是六张图片 直接看并没有什么信息 一个一个查看属性 没有找到有用信息 到winhexv里看一下 都是标准的png图片,而且没有fla ...

  4. Java实现 第十一届蓝桥杯——走方格(渴望有题目的大佬能给小编提供一下题目,讨论群:99979568)

    走方格 问题描述在平面上有一些二维的点阵. 这些点的编号就像二维数组的编号一样,从上到下依次为第 1 至第 n 行,从左到右依次为第1 至第 m 列,每一个点可以用行号和列号来表示. 现在有个人站在第 ...

  5. Java实现 第十一届蓝桥杯——超级胶水(渴望有题目的大佬能给小编提供一下题目,讨论群:99979568)

    PS: 好久没写过算法题了,总感觉自己写的思路没问题,但是结果就是不对,希望哪位大佬有时间能给找找问题 超级胶水 小明有n颗石子,按顺序摆成一排,他准备用胶水将这些石子黏在一起. 梅克什字有自己的重量 ...

  6. 2016年第七届蓝桥杯c/c++省赛B组

    2016年第七届蓝桥杯c/c++省赛B组 声明:以下答案是我自己做的.不能保证正确,须要參考正确答案的请到其它地方找. 第一题 :煤球数目 题目叙述: 有一堆煤球,堆成三角棱锥形.详细: 第一层放1个 ...

  7. 第六届蓝桥杯软件类省赛题解C++/Java

    第六届蓝桥杯软件类省赛题解C++/Java 1[C++].统计不含4的数字统计10000至99999中,不包含4的数值个数.答:暴力循环范围内所有数字判断一下就是了,答案是52488 1[Java]. ...

  8. Java实现 第十一届 蓝桥杯 (高职专科组)省内模拟赛

    有错误的或者有问题的欢迎评论 十六进制数1949对应的十进制数 19000互质的数的个数 70044与113148的最大公约数 第十层的二叉树 洁净数 递增序列 最大的元素距离 元音字母辅音字母的数量 ...

  9. Java 第十一届 蓝桥杯 省模拟赛 梅花桩

    小明每天都要练功,练功中的重要一项是梅花桩. 小明练功的梅花桩排列成 n 行 m 列,相邻两行的距离为 1,相邻两列的距离也为 1. 小明站在第 1 行第 1 列上,他要走到第 n 行第 m 列上.小 ...

随机推荐

  1. .NET Core 处理 WebAPI JSON 返回烦人的null为空

    前言 项目开发中不管是前台还是后台都会遇到烦人的null,数据库表中字段允许空值,则代码实体类中对应的字段类型为可空类型Nullable<>,如int?,DateTime?,null值字段 ...

  2. 有哪些适合个人开发的微信小程序

    微信小程序提供了一个简单.高效的应用开发框架和丰富的组件及API,帮助开发者在微信中开发具有原生 APP 体验的服务. 微信小程序支持采用云开发模式,无需后台服务,十分的方便快捷,适合个人开发一些工具 ...

  3. HP PROLIANT DL388 GEN10 (故障3019)SPP损坏

    HP PROLIANT DL388 GEN10 (故障3019)SPP损坏 1. 开机硬件自检,提示错误ERROR 3019: 2. 根据服务器版本GEN10下载最新固件SPP,可找服务商或者HP售后 ...

  4. 一条查询SQl是怎样执行的

    MySQL的逻辑架构图 大体来说,MySQL可以分为Server层和存储引擎层两部分. Server层包括连接器.查询缓存.分析器,优化器等,涵盖MySQL的大多核心服务功能,以及所有的内置函数,存储 ...

  5. MySQL45讲笔记-事务隔离级别,为什么你改了数据我看不见

    简单来说,事务就是要保证一组数据库操作,要么全部成功,要么全部失败.在MySQL中,事务至此是在引擎层实现的,但并不是所有的MySQL引擎都支持事务,这也是MyISAM被InnoDB取代的原因之一. ...

  6. logback为不同的包或类指定输出日志文件

    对日志分割的常见需求是,需要按不同的等级进行输出,这个的配置方式类似如下,在appender节点内添加内容 <appender name="FILE-INFO" class= ...

  7. ctfhub技能树—信息泄露—svn泄露

    打开靶机 查看页面信息 使用dvcs-ripper工具进行处理 ./rip-svn.pl -v -u http://challenge-3b6d43d72718eefb.sandbox.ctfhub. ...

  8. WMIC 查看bios配置信息

    如何查看我们的主板上的BIOS信息呢?有办法,不用安装任何软件,只需要windows自带的命令提示符就行,哈哈 WMIC BIOS LIST FULL /FORMAT:VALUE 如果第一次使用wmi ...

  9. USB过压保护芯片,高输入电压充电器(OVP)

    PW2606B是一种前端过电压和过电流保护装置.它实现了广泛的输入电压范围从2.5VDC到40VDC.过电压阈值可在外部或外部编程设置为内部默认设置.集成功率路径nFET开关的低电阻确保了更好的性能电 ...

  10. vue3.0改变概况

    一.slot API在render实现原理上的变化 二.全局API使用规范变化 三.Teleport添加 四.composition API变化 五.v-model变化