2018年蓝桥杯省赛A组(不断更新)
分数
http://oj.ecustacm.cn/problem.php?id=1359
水题
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
using namespace std;
int a[25];
int main(){
/*
int fz=0;
a[1]=1;
for(int i=2;i<=20;i++){
a[i]=2*a[i-1];
}
for(int i=1;i<=20;i++){
fz+=a[i];
}
int fm=1;
for(int i=0;i<19;i++){
fm*=2;
}
cout<<fm<<endl;
cout<<fz<<endl;
*/
cout<<"1048575/524288"<<endl;
return 0;
}
星期一
模拟即可
题目第一天是星期二
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
using namespace std;
int y=1901,m=1,d=1,s=2;
int res=0;
int k=0;
/*
1 3 5 7 8 10 12
2 4 6 9 11
*/
int fun(int x){
return x%400==0 || (x%4==0 &&x%100!=0);
}
int main(){
/*
while(y!=2000 || m!=12 || d!=31){
k++;
d++;
s++;
if(s==8) s=1;
if(s==1) res++;
if(m==12 && d==32){
y++,d=1,m=1;
continue;
}
if( (m==1 || m==3 || m==5 || m==7 || m==8 || m==10) && d==32){
m++;
d=1;
continue;
}
if( (m==4 || m==6 || m==9 || m==11) && d==31){
m++;
d=1;
continue;
}
if( m==2 && fun(y) && d==30){
m++;
d=1;
continue;
}
if(m==2 && !fun(y) && d==29){
m++;
d=1;
continue;
}
}
*/
int res=5217;
cout<<res;
return 0;
}
// freopen("testdata.in", "r", stdin);
乘积尾零
http://oj.ecustacm.cn/problem.php?id=1361
多少个0 就是看有多少质因数5(质因数2的数量不可能比5少 所以可以直接算有多少5就是答案)
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
using namespace std;
int x,res;
int fun(int x){
int n=0;
while(x%5==0){
x/=5;
n++;
}
return n;
}
int main(){
/*
while(cin>>x){
res+=fun(x);
}
*/
int res=31;
cout<<res;
return 0;
}
第几个幸运数
http://oj.ecustacm.cn/problem.php?id=1362
结果数据需要开long long
开一个优先队列不断的去生成幸运数,利用一个set保存幸运数(起到去重作用)
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<set>
using namespace std;
priority_queue<long long ,vector<long long>,greater<long long> >q;//小根堆写法
set <long long >s;
int num[3]={3,5,7};
int main(){
q.push(1);
s.insert(1);
for(long long i=1;;i++){
long long x=q.top();//取出当前队列最小值
q.pop();
if(x==59084709587505) {
cout<<i-1<<endl;
break;
}
for(int j=0;j<3;j++){
long long temp=x*num[j];//生成幸运数
if(!s.count(temp)){//生成的幸运数是之前没出现过的就加入
s.insert(temp);
q.push(temp);
}
}
}
return 0;
}
// freopen("testdata.in", "r", stdin);
航班时间
http://oj.ecustacm.cn/problem.php?id=1363
两次时间和除以二就是飞行时间。
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
using namespace std;
int get_time(){
string line;
getline(cin, line); //读一行
if(line.back() != ')') line += " (+0)";
int h1, m1, s1, h2, m2, s2, day;
sscanf(line.c_str(), "%d:%d:%d %d:%d:%d (+%d)", &h1, &m1, &s1, &h2, &m2, &s2, &day);
int S = h1*3600 + m1*60 + s1; //起飞时间:转为秒
int E = h2*3600 + m2*60 + s2; //到达时间:转为秒
return E - S + day*24*3600; //返回秒
}
int main(){
int n=0;
scanf("%d ",&n);
while(n--){
int ans =(get_time() + get_time())/2;
printf("%02d:%02d:%02d\n",ans/3600,ans/60%60,ans%60); //时:分:秒
}
return 0;
}
// freopen("testdata.in", "r", stdin);
三体攻击
http://oj.ecustacm.cn/problem.php?id=1364
三维差分 顶不住。
全球变暖
http://oj.ecustacm.cn/problem.php?id=1365
#include<bits/stdc++.h>
using namespace std;
int n;
char a[1010][1010]; //地图
int vis[1010][1010]={0}; //标记是否搜过
int d[4][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}}; //四个方向
int flag; //用于标记这个岛中是否被完全淹没
void dfs(int x, int y){
vis[x][y] = 1; //标记这个'#'被搜过。注意为什么可以放在这里
if(a[x][y+1]=='#' && a[x][y-1]=='#' && a[x+1][y]=='#' && a[x-1][y]=='#')
flag = 1; //上下左右都是陆地,不会淹没
for(int i = 0; i < 4; i++){ //继续DFS周围的陆地
int nx = x + d[i][0], ny = y + d[i][1];
//if(nx>=1 && nx<=n && ny>=1 && ny<=n && vis[nx][ny]==0 && a[nx][ny]=='#') //题目说边上都是水,所以不用这么写了
if(vis[nx][ny]==0 && a[nx][ny]=='#') //继续DFS未搜过的陆地,目的是标记它们
dfs(nx,ny);
}
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
cin >> a[i][j];
int ans = 0 ;
for(int i = 1; i <= n; i++) //DFS所有像素点
for(int j = 1; j <= n; j++)
if(a[i][j]=='#' && vis[i][j]==0){
flag = 0;
dfs(i,j);
if(flag == 0) //这个岛全部被淹
ans++; //统计岛的数量
}
cout<<ans<<endl;
return 0;
}

浙公网安备 33010602011771号