标题:等差素数列



2,3,5,7,11,13,....是素数序列。

类似:7,37,67,97,127,157 这样完全由素数组成的等差数列,叫等差素数数列。

上边的数列公差为30,长度为6。



2004年,格林与华人陶哲轩合作证明了:存在任意长度的素数等差数列。

这是数论领域一项惊人的成果!



有这一理论为基础,请你借助手中的计算机,满怀信心地搜索:



长度为10的等差素数列,其公差最小值是多少?

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

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

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

结果:210

代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
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<maxn;++i) {
if(num[i]) continue;
for(int j=i+i;j<maxn;j+=i) num[j]=1;
prime[index++]=i;
}
}
void slove() {
for(int d=2;d<1000;d+=2) {
for(int i=0;i<index;++i) {
int cnt=0,dis=d;
while(!num[prime[i]+dis]&&cnt<9) {
++cnt;
dis+=d;
}
if(cnt==9) {
printf("%d\n",d);
return;
}
}
}
}
int main() {
init();
slove();
return 0;
}

标题:承压计算



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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
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 <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] = 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<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
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<b.dd;
} else return a.mm<b.mm;
} else return a.yy<b.yy;
}
void slove(int y, int m, int d) {
int ty=y;
if(ty<=59) ty=20*100+y;
else ty=19*100+y;
if((ty%100==0&&ty%4==0)||(ty%400==0)) {
if(m>12) return;
if(ans[1][m]<d) return;
}
else {
if(m>12) return;
if(ans[0][m]<d) return;
}
bool exist=false;
for(int i=0;i<index;++i) {
if(bns[i].yy==ty&&bns[i].mm==m&&bns[i].dd==d) {
exist=true;
break;
}
}
if(!exist) {
bns[index].yy=ty;bns[index].mm=m;bns[index].dd=d;++index;
}
}
int main() {
int y,m,d;
scanf("%d/%d/%d",&y,&m,&d);
slove(y,m,d);
slove(d,y,m);
slove(d,m,y);
sort(bns,bns+index,cmp);
for(int i=0;i<index;++i) {
printf("%d-%02d-%02d\n",bns[i].yy,bns[i].mm,bns[i].dd);
}
return 0;
}

2017蓝桥杯省赛C/C++B(补题中)的更多相关文章

  1. 2017蓝桥杯 省赛D题(方格分割)

    6x6的方格,沿着格子的边线剪开成两部分.要求这两部分的形状完全相同. 如图:p1.png, p2.png, p3.png 就是可行的分割法.    试计算:包括这3种分法在内,一共有多少种不同的分割 ...

  2. 2017蓝桥杯 省赛C题(承压计算)

    X星球的高科技实验室中整齐地堆放着某批珍贵金属原料. 每块金属原料的外形.尺寸完全一致,但重量不同.金属材料被严格地堆放成金字塔形. 7 5 8 7 8 8 9 2 7 2 8 1 4 9 1 8 1 ...

  3. 第七届蓝桥杯省赛javaB组 第七题剪邮票

    剪邮票 如[图1.jpg], 有12张连在一起的12生肖的邮票.现在你要从中剪下5张来,要求必须是连着的.(仅仅连接一个角不算相连)比如,[图2.jpg],[图3.jpg]中,粉红色所示部分就是合格的 ...

  4. 2015年蓝桥杯省赛B组第3题--三羊献瑞

    三羊献瑞 观察下面的加法算式: 祥 瑞 生 辉   +   三 羊 献 瑞 -------------------    三 羊 生 瑞 气 (如果有对齐问题,可以参看[图1.jpg]) 其中,相同的 ...

  5. 第七届蓝桥杯省赛JavaB组——第十题压缩变换

    题目: 压缩变换小明最近在研究压缩算法.他知道,压缩的时候如果能够使得数值很小,就能通过熵编码得到较高的压缩比.然而,要使数值很小是一个挑战.最近,小明需要压缩一些正整数的序列,这些序列的特点是,后面 ...

  6. 52-2018 蓝桥杯省赛 B 组模拟赛(一)java

    最近蒜头君喜欢上了U型数字,所谓U型数字,就是这个数字的每一位先严格单调递减,后严格单调递增.比如 212212 就是一个U型数字,但是 333333, 9898, 567567, 313133131 ...

  7. 计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心

    问题描述 一天蒜头君得到 n 个字符串 si​,每个字符串的长度都不超过 10. 蒜头君在想,在这 n 个字符串中,以 si​ 为后缀的字符串有多少个呢? 输入格式 第一行输入一个整数 n. 接下来  ...

  8. 第九届蓝桥杯国赛+第二天的第11届acm省赛的总结

    第九届蓝桥杯国赛+第二天的第11届acm省赛的总结 25号坐的去北京的火车,10个小时的火车,然后挤了快两个小时的地铁,最终达到了中国矿业大学旁边的订的房间.12个小时很难受,晕车症状有点严重,吃了快 ...

  9. Python解答蓝桥杯省赛真题之从入门到真题(二刷题目一直更新)

    蓝桥刷题 原文链接: https://github.com/libo-sober/LanQiaoCup Python解答蓝桥杯省赛真题之从入门到真题 不同字串 """ 一 ...

随机推荐

  1. MongoDB复制

    1. 什么是复制 (1)MongoDB复制是将数据同步在多个服务器的过程. (2)复制提供了数据的冗余备份,并在多个服务器上存储数据副本,提高了数据的可用性, 并可以保证数据的安全性. (3)复制还允 ...

  2. LeetCode 628. Maximum Product of Three Numbers (最大三数乘积)

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  3. Mybatis通用Mapper

    极其方便的使用Mybatis单表的增删改查 项目地址:http://git.oschina.net/free/Mapper 优点? 不客气的说,使用这个通用Mapper甚至能改变你对Mybatis单表 ...

  4. virualbox 搭建 otter

    前言 为了学习otter,上一篇我们讲到了 otter 必要软件的安装,参考:virualbox 安装 otter 必备软件,现在安装otter,相比官方文档,我们尽量简化安装步骤. virualbo ...

  5. vue之地址栏#号问题

    mode的两个值 histroy:当你使用 history 模式时,URL 就像正常的 url,例如 http://jsapng.com/lms/,也好看! hash:默认'hash'值,但是hash ...

  6. Angular通信$q服务和promise对象

    promise 约定(promise)是一个对象,表示在未来时间点会发生的某件事情,约定可以是三种状态之一:等待.完成或拒绝.约定将从等待状态开始,然后可以转换为完成或者拒绝状态,一旦约定完成或者被拒 ...

  7. IE10和IE11中滑动条遮挡页面问题

    今天在开发的过程中前端项目,在小设备上会出现滑动条,这本没什么,在其他浏览器上都很正常,但是在IE10和IE11上出现了问题,发现侧边滑动条挡住了一部分页面的内容,因为侧边有要操作的按钮,这就是一个很 ...

  8. 两个HTML地址栏传中文参数乱码

    这个不叫乱码,我非专业.这个是url编码,js本身就是读取url编码的.对于js获取url的中文你可以尝试用escape() encodeURI() encodeURIComponent() deco ...

  9. zookeeper启动后的注意事项

    在各节点中运行zkServer.sh start后 1.首先看进程是否存在 QuorumPeerMain. 2.查看zookeeper的运行状态 zkServer.sh status,会出现一个lea ...

  10. Unity 游戏框架搭建 (七) 减少加班利器-QApp类

    本来这周想介绍一些框架中自认为比较好用的小工具的,但是发现很多小工具都依赖一个类----App. App类的职责: 1.接收Unity的生命周期事件. 2.做为游戏的入口. 3.一些框架级别的组件初始 ...