# 第十三届蓝桥杯大赛软件赛省赛C/C++大学B组真题（考后回顾）

## 试题 A: 九进制转十进制

``````1478
``````

## 试题 B: 顺子日期

``````#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
int main() {
int s = 20220101;
int e = 20221231;
int cnt = 0;
for(int i = s; i <= e; i++) {
int m = (i % 10000) / 100;
int d = (i % 100);
if(m > 12) continue;
if(d == 0 || d > a[m])continue;
string tmp = "";
int t = i;
while(t) {
int aa = t % 10;
tmp = tmp + (char)('0' + aa);
t = t / 10;
}
reverse(tmp.begin(),tmp.end());
int a1 = tmp.find("123");
//int a2 = tmp.find("321");
//int a3 = tmp.find("012");
//int a4 = tmp.find("210");
if(a1 != -1) {
cout<<i<<endl;
++cnt;
}
}
cout<<cnt<<endl;
}
``````

``````20220123
20221123
20221230
20221231
4
``````

## 试题 C: 刷题统计

``````#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
int main() {
ll a,b,n,ans = 0,km = 0;
cin>>a>>b>>n;
ll sum = a * 5 + b * 2;
ans = (n / sum) * 7;
km = n % sum;
int cnt = 0;
while(km > 0) {
++cnt;
if(cnt <= 5) km = km - a;
else km = km - b;
}
ans = ans + cnt;
cout<<ans<<endl;
return 0;
}
``````

## 试题 D: 修剪灌木

``````#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 1e4 + 10;
int ans[maxn];
void init(int n) {
int m = (n + 1) / 2;
for(int i = 1; i <= m; i++) {
int tmp = max(i,2 * (n - i));
ans[i] = tmp;
ans[n - i + 1] = tmp;
}
}
int main() {
int n;
cin>>n;
init(n);
for(int i = 1; i <= n; i++) cout<<ans[i]<<endl;
return 0;
}
``````

## 试题 E: X 进制减法

``````//呜呜呜呜，不会--
``````

## 试题 F: 统计子矩阵

``````#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define mod 1000000007
const int maxn = 5e2 + 10;
int vis[maxn][maxn],n,m,k;
int cal(int x,int y,int i,int j) {return vis[i][j] - vis[i][y-1] - vis[x - 1][j] + vis[x-1][y-1];}
int init() {
int ans;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
for(int l = i; l <= n; l++)
for(int s= j; s <= m; s++) {
int sum = cal(i,j,l,s);
if(sum <= k) ans++;
}
}
}
return ans;
}
int main() {
cin>>n>>m>>k;
for(int i = 1; i <=n; i++) {
for(int j = 1; j <= m; j++) {
int x;
cin>>x;
vis[i][j] = vis[i-1][j] + vis[i][j-1] - vis[i-1][j-1] + x;
}
}
int num = init();
cout<<num<<endl;
return 0;
}
``````

## 试题 G: 积木画

``````#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define mod 1000000007
const int maxn = 1e7 + 10;
ll n;
int main() {
cin>>n;
if(n == 1) {
cout<<"1"<<endl;
} else if(n == 2) {
cout<<"2"<<endl;
} else if(n == 3){
cout<<"5"<<endl;
} else if(n == 4) {
cout<<"11"<<endl;
} else {
ll a = 1,b = 2,c = 5,ans;
for(int i = 4; i <= n; ++i) {
ans = (c * 2 + a) % mod;
a = b % mod;
b = c % mod;
c = ans % mod;
}
cout<<(ans % mod)<<endl;
}
return 0;
}

``````

## 试题 H: 扫雷

``````#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define mod 1000000007
double len(double x,double y,double i,double j) {return abs(x-i)*abs(x-i)+abs(y-j)*abs(y-j);}
const int maxn = 5e4 + 10;
ll cnt,n,m;
int vis[maxn];
struct BOBO{
double x,y,z;
}M[maxn];
void init(double x,double y,double r) {
for(int i = 0; i < n; i++) {
if(vis[i] || len(x,y,M[i].x,M[i].y) > r * r) continue;
cnt++;
vis[i] = 1;
init(M[i].x,M[i].y,M[i].z);
}
}
int main() {
cin>>n>>m;
for(int i = 0; i < n; i++) cin>>M[i].x>>M[i].y>>M[i].z;
while(m--){
double x,y,z;
cin>>x>>y>>z;
init(x,y,z);
}
cout<<cnt<<endl;
return 0;
}
``````

## 试题 I: 李白打酒加强版

2014年李白打酒，2022年李白打酒加强版。

``````#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007
const int maxn = 1e7 + 10;
ll n,m,ans;
void init(){
int t = 1 << (n+m);
ll cd,cs,tmp;
for(ll i = 0; i < t; i++) {
tmp = 2;
cd = cs = 0;
int mark = 1;
for(ll j = 0; j < n + m; j++) {
if(!mark) break;
if(i >> j & 1){
tmp = tmp * 2;
cd++;
if(j == n+m-1) mark = 0;
}
else {
if(tmp <= 0) mark = 0;
tmp--;
cs++;
}
}
if(mark && cs == m && cd == n && !tmp) ans = (ans + 1) % mod;;
}
}
int main() {
cin>>n>>m;
init();
cout<<ans<<endl;
return 0;
}
``````

## 试题 J: 砍竹子

``````//不会------
``````

AcWing上有第十三届蓝桥杯大赛软件赛省赛C/C++大学B组的原题，大家可以自测一下

2022年5月7日

THE END