2017蓝桥杯省赛C/C++B(补题中)
发布日期:2021-05-09 04:20:35 浏览次数:23 分类:博客文章

本文共 5442 字,大约阅读时间需要 18 分钟。

标题:等差素数列
2,3,5,7,11,13,....是素数序列。
类似:7,37,67,97,127,157 这样完全由素数组成的等差数列,叫等差素数数列。
上边的数列公差为30,长度为6。
2004年,格林与华人陶哲轩合作证明了:存在任意长度的素数等差数列。
这是数论领域一项惊人的成果!
有这一理论为基础,请你借助手中的计算机,满怀信心地搜索:
长度为10的等差素数列,其公差最小值是多少?

注意:需要提交的是一个整数,不要填写任何多余的内容和说明文字。

思路:筛法打表+枚举公差

(比赛的时候不知道哪里写错了,死活跑不出来结果,+_+)

结果:210

代码:

#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=1e6;int num[maxn];int prime[maxn];int index;void init() { num[0]=1; num[1]=1; index=0; for(int i=2;i
标题:承压计算
X星球的高科技实验室中整齐地堆放着某批珍贵金属原料。
每块金属原料的外形、尺寸完全一致,但重量不同。
金属材料被严格地堆放成金字塔形。
7
5 8
7 8 8
9 2 7 2
8 1 4 9 1
8 1 8 8 4 1
7 9 6 1 4 5 4
5 6 5 5 6 9 5 6
5 5 4 7 9 3 5 5 1
7 5 7 9 7 4 7 3 3 1
4 6 4 5 5 8 8 3 2 4 3
1 1 3 3 1 6 6 5 5 4 4 2
9 9 9 2 1 9 1 9 2 9 5 7 9
4 3 3 7 7 9 3 6 1 3 8 8 3 7
3 6 8 1 5 3 9 5 8 3 8 1 8 3 3
8 3 2 3 3 5 5 8 5 4 2 8 6 7 6 9
8 1 8 1 8 4 6 2 2 1 7 9 4 2 3 3 4
2 8 4 2 2 9 9 2 8 3 4 9 6 3 9 4 6 9
7 9 7 4 9 7 6 6 2 8 9 4 1 8 1 7 2 1 6
9 2 8 6 4 2 7 9 5 4 1 2 5 1 7 3 9 8 3 3
5 2 1 6 7 9 3 2 8 9 5 5 6 6 6 2 1 8 7 9 9
6 7 1 8 8 7 5 3 6 5 4 7 3 4 6 7 8 1 3 2 7 4
2 2 6 3 5 3 4 9 2 4 5 7 6 6 3 2 7 2 4 8 5 5 4
7 4 4 5 8 3 3 8 1 8 6 3 2 1 6 2 6 4 6 3 8 2 9 6
1 2 4 1 3 3 5 3 4 9 6 3 8 6 5 9 1 5 3 2 6 8 8 5 3
2 2 7 9 3 3 2 8 6 9 8 4 4 9 5 8 2 6 3 4 8 4 9 3 8 8
7 7 7 9 7 5 2 7 9 2 5 1 9 2 6 5 3 9 3 5 7 3 5 4 2 8 9
7 7 6 6 8 7 5 5 8 2 4 7 7 4 7 2 6 9 2 1 8 2 9 8 5 7 3 6
5 9 4 5 5 7 5 5 6 3 5 3 9 5 8 9 5 4 1 2 6 1 4 3 5 3 2 4 1
X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X
其中的数字代表金属块的重量(计量单位较大)。
最下一层的X代表30台极高精度的电子秤。
假设每块原料的重量都十分精确地平均落在下方的两个金属块上,
最后,所有的金属块的重量都严格精确地平分落在最底层的电子秤上。
电子秤的计量单位很小,所以显示的数字很大。
工作人员发现,其中读数最小的电子秤的示数为:2086458231
请你推算出:读数最大的电子秤的示数为多少?
注意:需要提交的是一个整数,不要填写任何多余的内容。

思路:找出的最小值并不是题目中给出的数据,他们之间存在着倍数关系(电子秤的计量单位很小),倍数关系乘寻找出来的最大值即可。需要注意的是要用double,我被误

导用了long long,结果爆了。吸取教训吧。

结果:72665192664

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int main() { double a[30][30]; for(int i=0;i<29;++i) { for(int j=0;j<=i;++j) { scanf("%lf",&a[i][j]); } } for(int i=0;i<29;++i) { for(int j=0;j<=i;++j) { a[i+1][j]+=(a[i][j]*1.0)/(2.0); a[i+1][j+1]+=(a[i][j]*1.0)/(2.0); } } double minvalue=99999; double maxvalue=-1; for(int i=0;i<=29;i++) { minvalue=min(minvalue,a[29][i]); maxvalue=max(maxvalue,a[29][i]); } printf("%lf\n",maxvalue*(2086458231*1.0/minvalue)); return 0;}
标题:取数位
求1个整数的第k位数字有很多种方法。
以下的方法就是一种。
// 求x用10进制表示时的数位长度
int len(int x){
    if(x<10) return 1;
    return len(x/10)+1;
}
    
// 取x的第k位数字
int f(int x, int k){
    if(len(x)-k==0) return x%10;
    return _____________________;  //填空
}
    
int main()
{
    int x = 23574;
    printf("%d\n", f(x,3));
    return 0;
}
对于题目中的测试数据,应该打印5。
请仔细分析源码,并补充划线部分所缺少的代码。
注意:只提交缺失的代码,不要填写任何已有内容或说明性的文字。

结果:f(x/10,k)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;int len(int x){ if(x<10) return 1; return len(x/10)+1;}// 取x的第k位数字int f(int x, int k){ if(len(x)-k==0) return x%10; return f(x/10,k); //填空}int main(){ int x = 23574; printf("%d\n", f(x,3)); return 0;}
标题:最大公共子串
最大公共子串长度问题就是:
求两个串的所有子串中能够匹配上的最大长度是多少。
比如:"abcdkkk" 和 "baabcdadabc",
可以找到的最长的公共子串是"abcd",所以最大公共子串长度为4。
下面的程序是采用矩阵法进行求解的,这对串的规模不大的情况还是比较有效的解法。
请分析该解法的思路,并补全划线部分缺失的代码。
#include <stdio.h>
#include <string.h>
#define N 256
int f(const char* s1, const char* s2)
{
    int a[N][N];
    int len1 = strlen(s1);
    int len2 = strlen(s2);
    int i,j;
    
    memset(a,0,sizeof(int)*N*N);
    int max = 0;
    for(i=1; i<=len1; i++){
        for(j=1; j<=len2; j++){
            if(s1[i-1]==s2[j-1]) {
                a[i][j] = __________________________;  //填空
                if(a[i][j] > max) max = a[i][j];
            }
        }
    }
    
    return max;
}
int main()
{
    printf("%d\n", f("abcdkkk", "baabcdadabc"));
    return 0;
}
注意:只提交缺少的代码,不要提交已有的代码和符号。也不要提交说明性文字。
结果:a[i-1][j-1]+1

#include 
#include
#define N 256int f(const char* s1, const char* s2){ int a[N][N]; int len1 = strlen(s1); int len2 = strlen(s2); int i,j; memset(a,0,sizeof(int)*N*N); int max = 0; for(i=1; i<=len1; i++){ for(j=1; j<=len2; j++){ if(s1[i-1]==s2[j-1]) { a[i][j] = a[i-1][j-1]+1; //填空 if(a[i][j] > max) max = a[i][j]; } } } return max;}int main(){ printf("%d\n", f("abcdkkk", "baabcdadabc")); return 0;}
标题:日期问题
小明正在整理一批历史文献。这些历史文献中出现了很多日期。小明知道这些日期都在1960年1月1日至2059年12月31日。令小明头疼的是,这些日期采用的格式非常不统一,有采用年/月/日的,有采用月/日/年的,还有采用日/月/年的。更加麻烦的是,年份也都省略了前两位,使得文献上的一个日期,存在很多可能的日期与其对应。  
比如02/03/04,可能是2002年03月04日、2004年02月03日或2004年03月02日。  
给出一个文献上的日期,你能帮助小明判断有哪些可能的日期对其对应吗?
输入
----
一个日期,格式是"AA/BB/CC"。  (0 <= A, B, C <= 9)  
输出
----
输出若干个不相同的日期,每个日期一行,格式是"yyyy-MM-dd"。多个日期按从早到晚排列。  
样例输入
----
02/03/04  
样例输出
----
2002-03-04  
2004-02-03  
2004-03-02  
资源约定:
峰值内存消耗(含虚拟机) < 256M
CPU消耗  < 1000ms
请严格按要求输出,不要画蛇添足地打印类似:“请您输入...” 的多余内容。
注意:
main函数需要返回0;
只使用ANSI C/ANSI C++ 标准;
不要调用依赖于编译环境或操作系统的特殊函数。
所有依赖的函数必须明确地在源文件中 #include <xxx>
不能通过工程设置而省略常用头文件。
提交程序时,注意选择所期望的语言类型和编译器类型。

思路:注意闰年,然后排序

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=1e3+5;struct node { int yy,mm,dd;}bns[maxn];int ans[2][13]={{0,31,30,31,30,31,30,31,31,30,31,30},{0,31,29,31,30,31,30,31,31,30,31,30}};int index=0;bool cmp(node a, node b) { if(a.yy==b.yy) { if(a.mm==b.mm) { return a.dd
12) return; if(ans[1][m]
12) return; if(ans[0][m]

上一篇:2016第七届 蓝桥杯 全国总决赛B题(完全平方数) (练习)
下一篇:zzuli 1815: easy problem 打表

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月18日 15时08分58秒