B. 明码 #STL

题意

把每个字节转为2进制表示,1表示墨迹,0表示底色。每行2个字节,一共16行,布局是:

第1字节,第2字节
第3字节,第4字节
....
第31字节, 第32字节

给定一段由多个汉字组成的信息,每个汉字用\(32\)个字节表示,这里给出了字节作为有符号整数的值。题目的要求隐藏在这些信息中。你的任务是复原这些汉字的字形,从中看出题目要求,并根据要求填写答案。

分析

注意题目中说明是有符号二进制,也就说如果某个十进制数为负数,则它的二进制为补码(对于负数的补码,最高位为符号位,要取1,对原码取反再加一)。

题目简而言之,即为每一行有\(32\)个数字,每两个数字组成一行的布局。比如

第一行:4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0
则每两个作为一行,并换算成二进制:
00000100 00000000
00000100 00000000
00000100 00000000
00000100 00100000
11111111 11110000
00000100 00100000
00000100 00100000
00000100 00100000
00000100 00100000
00000100 00100000
00001000 00100000
00001000 00100000
00010000 00100010
00010000 00100010
00100000 00011110
11000000 00000000
每个1组成汉字的笔画,所以这一行的字为“九”

关于十进制对二进制的转换,可以使用STL的bitset数据结构,十分方便,初始时定义为8位的二进制串,每次输入一个十进制,它就能将该数值转换为二进制串,同时还能将这个二进制串输出来!

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int main() {
//打印出来
for(int i = 1; i <= 10; i++){
for(int j = 1; j <= 16; j++){
for(int a = 1; a <= 2; a++){
int tmp; scanf("%d", &tmp);
bitset<8> mybit(tmp);
cout << mybit << ' ';
}
cout << endl;
}
cout << "----------------" << endl;
}
//cout << "九的九次方等于多少?" << endl;
//cout << "387420489" << endl; //最终结果
return 0;
}

C. 乘积尾零 #因数分解

题意

如下的10行数据,每行有10个整数,请你求出它们的乘积的末尾多少个零?

5650 4542 3554 473 946 4114 3871 9073 90 4329
2758 7949 6113 5659 5245 7432 3051 4434 6704 3594
9937 1173 6866 3397 4759 7557 3070 2287 1453 9899
1486 5722 3135 1170 4014 5510 5120 729 2880 9019
2049 698 4582 4346 4427 646 9742 7340 1230 7683
5693 7015 6887 7381 4172 4341 2909 2027 7355 5649
6701 6645 1671 5978 2704 9926 295 3125 3878 6785
2066 4247 4800 1578 6652 4616 1113 6205 3264 2915
3966 5291 2904 1285 2193 1428 2265 8730 9436 7074
689 5510 8243 6114 337 4096 8199 7313 3685 211

分析

注意审题,题目要求的是乘积结果的尾部,也就说它并不是问你乘积结果整个数字含有多少个零!(如果是求这个的话,难度++)

观察到,乘积结果的尾部有\(x\)个\(0\),说明该乘积结果含有\(x\)个因子\(10\),也就说至少含有\(x\)个因子\(5\)和\(x\)个因子\(2\)(多余的因子成单,没有与之对应的因子进行配对),由此我们可以将所有数中的因子\(5\)和\(2\)分解出来,统计含\(2\)和\(5\)的因子数量并取两者最少值,即能推出乘积结果尾部\(0\)的数量。

举个栗子,对于\(1050=2\times3\times7\times5\times5\)(含两个\(5\),一个\(2\)),而\(180=9\times2\times2\times5\)(含一个\(5\),两个\(2\)),则他们的乘积为\(1050\times180=189000=(9\times3\times7)\times(5\times2)\times(5\times2)\times(5\times2)\)(即三对\(5\times2\)构成尾部的三个\(0\))

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int ResoluteNumber(int cur, int base){
int res = 0; //统计数cur中含有多少个base因子
while(cur % base == 0){
res ++;
cur /= base;
}
return res;
}
int num_2, num_5;
int main(){
freopen("C:\\Learning\\data.in", "r", stdin);
for(int i = 1, tmp; i <= 100; i++){
scanf("%d", &tmp);
num_2 += ResoluteNumber(tmp, 2); //统计tmp含有多少个2因子
num_5 += ResoluteNumber(tmp, 5); //统计tmp含有多少个5因子
}
printf("%d\n", min(num_2, num_5));
//printf("31\n"); //最终结果
return 0;
}

D. 测试次数 #记忆化搜索 #动态规划

迟一点再更

鸡蛋掉落

普通记忆化搜索

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int dp[1005][4], n = 1000, m = 3;
int DFS(int floor, int num){
if(num == 0) return 0;
if(num == 1 || floor <= 1) return floor;
if(dp[floor][num] < INF) return dp[floor][num];
int ans = 0x3f3f3f3f;
for(int i = 1; i <= floor; i++){
int badcase = max(DFS(i - 1, num - 1), DFS(floor - i, num));
ans = min(ans, badcase + 1);
}
return dp[floor][num] = ans;
}
int main(){
memset(dp, 0x3f, sizeof(dp));
printf("%d\n", DFS(n, m));
}

记忆化搜索+二分思想+哈希表 过大数据

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int n = 1000, m = 3;
unordered_map<ll, int> dp;
int DFS(int floor, int num){
if(num == 0) return 0;
if(num == 1 || floor <= 1) return floor;
if(dp.find(1LL * floor * 10005 + (ll)num) != dp.end()) return dp[1LL * floor * 10005 + (ll)num];
int ans = 0x3f3f3f3f, lo = 1, hi = floor + 1;
while(lo < hi){
int mid = (lo + hi) >> 1;
int rev_1 = DFS(mid - 1, num - 1);
int rev_2 = DFS(floor - mid, num);
if (rev_1 < rev_2) lo = mid + 1;
else hi = mid;
}
int badcase_1 = max(DFS(lo - 1, num - 1), DFS(floor - lo, num));
int badcase_2 = max(DFS(hi - 1, num - 1), DFS(floor - hi, num));
ans = 1 + min(badcase_1, badcase_2);
return dp[1LL * floor * 10005 + (ll)num] = ans;
}
int main(){
printf("%d\n", DFS(n, m));
}

F. 递增三元组 #二分思想 #前缀和

题意

给定三个整数数组A = [A1, A2, ... AN], B = [B1, B2, ... BN],

C = [C1, C2, ... CN](\(N\leq1e5\)),请你统计有多少个三元组$(i, j, k) $同时满足:

  • \(1 \leq i, j, k \leq N\)

  • \(A_i < B_j < C_k\)

分析

不妨对这三个整数数组先升序排序,我们知道,要确定一个三元组\((i,j,k)\),那么可以先从\(A\)中取一个元素\(a_i\),再从\(B\)中找出第一个大于等于\(a_i\)的元素\(b_j\),同理再从\(C\)中找出第一个大于等于\(b_j\)的元素\(c_k\)。但如果这样直接枚举每个\(i,j,k\)一定会超时。

我们枚举每个\(b_j\),通过二分确定了第一个\(c_k\)的位置\(pos\),可以知道有\((n-pos)\)个C数组元素,大于等于\(b_j\)。我们在枚举\(b_j\)并确定\(pos\)的过程中,同时用前缀和维护前\(j\)个元素\(b_j\),有多少个小于C数组的元素(\(sum[j]=\sum_{1}^j{n-pos}\))。

接着,枚举每个$ a_i\(,通过二分确定了第一个\)b_j\(的位置\)posB\(,查询\)sum[n]-sum[posB]$,可以知道满足题目要求的三元组个数。

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[MAXN], b[MAXN], c[MAXN];
ll ans = 0, sumFromB[MAXN],sum[MAXN]; //sumFromB[i]表示,对于B数组中第i个元素bi,在C数组中大于等于它的元素数量。 int main(){
int n; scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
for(int i = 1; i <= n; i++) scanf("%d", &c[i]);
sort(a+1, a+1+n); sort(b+1, b+1+n); sort(c+1, c+1+n);
for(int i = 1; i <= n; i++){
int posC = upper_bound(c+1, c+1+n, b[i]) - c; //通过二分,从C数组中找到第一个大于等于bi的元素位置pos
sumFromB[i] = n - posC + 1; //说明C数组中[pos, n]的元素,都满足大于等于bi。
}
for(int i = 1; i <= n; i++){
sum[i] = sum[i - 1] + sumFromB[i]; //前缀和,对于B数组前i个元素,统计大于等于它们的C数组元素个数
}
for(int i = 1; i <= n; i++){
int posB = upper_bound(b+1, b+1+n, a[i]) - b;//通过二分,从C数组中找到第一个大于等于ai的元素位置posB
ans += (sum[n] - sum[posB - 1]); //利用前缀和,求出[posB,n]中满足三元组的个数
}
printf("%lld\n", ans);
return 0;
}

G. 螺旋折线 #性质观察 #等差数列

题意

如下图所示的螺旋折线经过平面上所有整点恰好一次,对于整数点\((x,y)\)(\(-1e9\leq x, y\leq 1e9\)),定义它到原点的距离:\(dix(x,y)\),为从原点到\((x, y)\)的螺旋折线段的长度。

分析

一开始我按路径递增去模拟,只要转向次数为偶数次,就对前进长度+1,但还是超时,下面就是我的75分qaq。

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
ll dx[] = { 0, -1, 0, 1, 0 };
ll dy[] = { 0, 0, 1, 0, -1 };
int main() {
ll len = 0, sum = 0;
ll cur_x = 0, cur_y = 0;
ll des_x = 0, des_y = 0;
scanf("%lld%lld", &des_x, &des_y);
int t = 0;
while (1) {
t++; if (t > 4) t = 1;
if ((t - 1) % 2 == 0) len++; ll step = len;
if (abs(des_y - cur_y) == 0) {
if((cur_x < des_x && des_x < cur_x + step * dx[t]) ||
(cur_x > des_x && des_x > cur_x + step * dx[t]) )
step = min(step, (ll)abs(des_x - cur_x));
}
else if (abs(des_x - cur_x) == 0) {
if ((cur_y < des_y && des_y < cur_y + step * dy[t]) ||
(cur_y > des_y && des_y > cur_y + step * dy[t]))
step = min(step, (ll)abs(des_y - cur_y));
}
cur_x += step * dx[t];
cur_y += step * dy[t];
sum += step; if (cur_x == des_x && cur_y == des_y) break;
}
printf("%lld\n", sum);
return 0;
}

参考了@虎老狮的思路。我们可以将折线每一行的左下角长度为\(1\)的线段顺时针旋转90度(见下图),于是螺旋折线就变成长度易求的正方形环条了。于是点在螺旋折线上的移动就转化为一个点从每一个正方形环的左下角作为起点,顺时针移动,移动整一个环后,便直接跳到下一个更长的正方形环的左下角起点,…. 。容易观察到每一条正方形环的周长组成了以0为首项(即第一个正方形环是空的),以8为公差的等差数列。

如上图,我们假设点A\((x_i,y_i)\)在该正方形对角线上侧,那么题目要求的\(dis(x_i, y_i)\),实际上就是(第三条边左下角起点出发到达点\((x_i,y_i)\)的距离)+(不包括第三条边的内部正方形的周长之和)。由等差数列求和公式,内部边的长度之和就是\(S_i = \frac{(0 + (i-1)\times8)\times(i-1)}{2}\)。第三条边左下角起点出发到达点\((x_i,y_i)\)的距离,就是\((i+x_i)+(i+y_i)\)。如果是位于正方形对角线下侧的点B\((x_j,y_j)\),它需要用第三条边的周长减去\((j+x_j)+(j+y_j)\)

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <set>
#include <cmath>
#include <bitset>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
ll des_x, des_y, ans;
int main(){
scanf("%lld%lld", &des_x, &des_y);
ll n = max(abs(des_x), abs(des_y));
ll innerSqure = 4 * 1LL * (n - 1) * n;// = (0 + (n - 1) * 8) * (n - 1) / 2;
ll dis_x = n + des_x, dis_y = n + des_y;
if(des_y >= des_x)
ans += (dis_x + dis_y);
else
ans += (8 * 1LL * n - dis_x - dis_y);
printf("%lld\n", ans + innerSqure);
return 0;
}

2018年第九届蓝桥杯【C++省赛B组】B、C、D、F、G 题解的更多相关文章

  1. 关于2018年第九届蓝桥杯[C++省赛B组][第四题:测试次数]的疑问

    题目来源:https://blog.csdn.net/qq_34202873/article/details/79784548 #标题:测试次数#x星球的居民脾气不太好,但好在他们生气的时候唯一的异常 ...

  2. 2018年第九届蓝桥杯B组题C++汇总解析-fishers

    2018年第九届蓝桥杯B组题C++解析-fishers 题型 第一题:第几天 第二题:明码 第三题:乘积尾零 第四题:测试次数 第五题:快速排序 第六题:递增三元组 第七题:螺旋折线 第八题:日志统计 ...

  3. 2018年第九届蓝桥杯题目(C/C++B组)汇总

    第一题 标题:第几天 2000年的1月1日,是那一年的第1天. 那么,2000年的5月4日,是那一年的第几天? 注意:需要提交的是一个整数,不要填写任何多余内容. 解题思路: 1.  判断2月有几天, ...

  4. 2018第九届蓝桥杯决赛(C++ B组)

    逛了大半个北京还是挺好玩de 第一题 标题:换零钞 x星球的钞票的面额只有:100元,5元,2元,1元,共4种. 小明去x星旅游,他手里只有2张100元的x星币,太不方便,恰好路过x星银行就去换零钱. ...

  5. 2018年第九届蓝桥杯B组第四题:摔手机题解

    摔手机 摔手机 动态规划  在蓝桥杯的时候遇到一次 当时没有做对  看了题解也没明白  如今再次遇到这个类似的题目 于是拿出来补补吧 摔手机题目如下: 星球的居民脾气不太好,但好在他们生气的时候唯一的 ...

  6. 2018年第九届蓝桥杯国赛总结(JavaB组)

    懒更,之前的删了补一个国赛总结 记yzm10的第一次国赛(赛点:首都经贸大学) 第一次就拿到了国一,运气不要太好~(同组lz学长豪取国特orz) 从省赛一路水过来,总算有了点成绩.其实最后一题有些遗憾 ...

  7. 2018年第九届蓝桥杯【C++省赛B组】(未完)

    第一题 标题:第几天 2000年的1月1日,是那一年的第1天. 那么,2000年的5月4日,是那一年的第几天? 注意:需要提交的是一个整数,不要填写任何多余内容 利用excel更加快捷: 答案是125 ...

  8. 2018年第九届蓝桥杯【C++省赛B组】

    2标题:明码 汉字的字形存在于字库中,即便在今天,16点阵的字库也仍然使用广泛.16点阵的字库把每个汉字看成是16x16个像素信息.并把这些信息记录在字节中. 一个字节可以存储8位信息,用32个字节就 ...

  9. 2018年第九届蓝桥杯C/C++A组省赛(最后一题)

    第十题 付账问题   [题目描述]    几个人一起出去吃饭是常有的事.但在结帐的时候,常常会出现一些争执.    现在有 n 个人出去吃饭,他们总共消费了 S 元.其中第 i 个人带了 ai 元.幸 ...

  10. 2018年第九届蓝桥杯【C++省赛B组】【第二题:明码】

    参考:https://blog.csdn.net/qq_34202873/article/details/79784242 #include <bits/stdc++.h> using n ...

随机推荐

  1. 【应用服务 App Service】App Service证书导入,使用Key Vault中的证书

    问题描述 正常情况下,如果需要为应用服务安装SSL证书,可以在证书准备好的情况,通过门户上传即可,详细步骤可以参考微软官方文档(在 Azure 应用服务中添加 TLS/SSL 证书:https://d ...

  2. Docker学习笔记之--.Net Core项目容器连接mssql容器(环境:centos7)

    前一节演示在docker中安装mssql,地址:Docker学习笔记之--安装mssql(Sql Server)并使用Navicat连接测试(环境:centos7) 本节演示 .Net Core项目容 ...

  3. Python ( 高级 第二部)

    目录 模块和包 面向对象 部分一: 面向对象程序开发 面向对象封装: 对象的相关操作 面向对象封装: 类的相关操作 实例化的对象/ 定义的类删除公有成员属性和公有成员方法 部分二: 单继承 多继承 菱 ...

  4. Java实现评论回复功能

    目录 一.分类方式 1.单一型 2.嵌套型 3.两层型 二.实现原理 1.单一型 2.嵌套型 3.两层型 使用递归循环开发评论回复功能,适用于大部分的简单单体应用 评论功能或许是大多数的单体应用之中会 ...

  5. 简单Emacs配置

    (global-set-key [f9] 'compile-file) (global-set-key [f10] 'gud-gdb) (global-set-key (kbd "C-s&q ...

  6. 想springboot启动完成后执行某个方法

    如题,很多时候,我们都需要在springboot项目启动后初始化化一些自己的数据 原文地址:https://www.jianshu.com/p/f80f833ab8f6 实现方法有2个. 一.Appl ...

  7. 如何将别人Google云端硬盘中的数据进行保存

    查了好久终于知道! 如何将别人Google云端硬盘中的数据进行copy,而不是右键发现只有添加快捷方式 只要shift+z就可以保存了! 之后等我弄清楚怎么将别人家的云盘中的数据集导到colab再来详 ...

  8. 【SpringBoot】13. logback日志记录

    logback日志记录 Spring Boot 1.5.19.RELEASE 1.导入相关jar包 在spring-boot-starter-web 中已经包含 2.添加logback.xml配置文件 ...

  9. C++ 数据结构 4:排序

    1 基本概念 1.1 定义 排序是计算机内经常进行的一种操作,其目的是将一组"无序"的数据元素调整为"有序"的数据元素. 1.2 数学定义 假设含n个数据元素的 ...

  10. SpringBoot+MySQL,如何整合并使用MyBatis框架

    概述 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. MyBatis 可以使用简单的 ...