2020蓝桥杯省赛 B 组计蒜客模拟赛(一)目录

  • 试题 A:有趣的数字(结果填空)
  • 试题 B:爬楼梯(结果填空)
  • 试题 C:七巧板(结果填空)
  • 试题 D:苹果(结果填空)
  • 试题 E:方阵(结果填空)
  • 试题 F:寻找重复项(程序设计)
  • 试题 G:被袭击的村庄(程序设计)
  • 试题 H:字符串(程序设计)
  • 试题 I:最短路(程序设计)
  • 试题 J:迷宫(程序设计)

试题 A:有趣的数字(结果填空)

题意:点此进入
我们称一个数是质数,而且数位中出现了 5 的数字是有趣的。例如 5, 59, 457 都是有趣的,而 15, 7不是。求 1到 100000 中有趣的数的个数。

做法:用筛法把素数筛出来再判断数位中含不含5。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
const LL Mod = 1e9+7;
const int M = 3e5+10;
int a[N];
int check(int x) {while(x) {if(x % 10 == 5) return 1;x /= 10;}return 0;
}
int main() {for(int i = 2; i*i < N; ++i) {if(!a[i]) {for(int j = i+i; j < N; j += i) a[j] = 1;}}int ans = 0;for(int i = 5; i <= 100000; ++i) {if(!a[i] && check(i)) cout << i << " ", ++ans;}cout << endl << ans;return 0;
}

答案:3282

试题 B:爬楼梯(结果填空)

题意:点此进入
蒜头君要爬楼梯。楼梯一共有 10 层台阶。因为腿长的限制,每次最多能上 4 层台阶。但是第 5,7 层楼梯坏掉了不能踩。求上楼梯的方案数。

做法:从i-4~i-1状态转移过来。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
const LL Mod = 1e9+7;
const int M = 3e5+10;
int dp[20];
int main() {dp[0] = 1;_rep(1, 10, i) {if(i == 5 || i == 7) continue;_rep(max(i-4, 0), i-1, j) {dp[i] += dp[j];}}cout << dp[10];return 0;
}

答案:72

试题 C:七巧板(结果填空)

题意:点此进入

做法:会发现加一根直线是多了6个区域,加两根直线是多了7个区域,所以就是 7(+6+7+8+9+10)。

答案:47

试题 D:苹果(结果填空)

题意:点此进入
有 30 个篮子,每个篮子里有若干个苹果,篮子里的苹果数序列已经给出。
现在要把苹果分给小朋友们,每个小朋友要么从一个篮子里拿三个苹果,要么从相邻的三个篮子里各拿一个苹果。
苹果可以剩余,而且不同的拿法会导致不同的答案。比如对于序列3 1 3 ,可以分给两个小朋友变成0 1 0;也可以分给一个小朋友变成2 0 2,此时不能继续再分了。所以答案是 2 。
求问对于以下序列,最多分给几个小朋友?

7 2 12 5 9 9 8 10 7 10 5 4 5 8 4 4 10 11 3 8 7 8 3 2 1 6 3 9 7 1

做法:这题一开始WA了很多次,我一开始试过先优先相邻三个取完,再来单个单个的取,发现这样是59,WA,然后换了一种方式,先单个单个取,再相邻三个取,这样57,WA,正解是对于每个单个单个取完就考虑三个相邻的,这样结果是62,三者取最大,但我也想不到这最后一种啊 ,更正确的做法应该是dp把,可惜我不会 。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
const LL Mod = 1e9+7;
const int M = 3e5+10;
int a[32] = {0, 7, 2, 12, 5, 9, 9, 8, 10, 7, 10, 5, 4, 5, 8, 4, 4, 10, 11, 3, 8, 7,8,3,2,1,6,3,9,7,1};
int main() {int ans = 0;_rep(1, 30, i) {ans += a[i] / 3, a[i] %= 3;if(a[i] && a[i+1] && a[i+2]) {int mid = min(a[i], min(a[i+1], a[i+2]));ans += mid; a[i+2] -= mid; a[i+1] -= mid; a[i] -= mid;}}cout << ans << endl;return 0;
}

答案:62

试题 E:方阵(结果填空)

题意:点此进入

做法:这题也是做不出来系列 ,想过找规律,但是没找出来,如果两点能够看见一定是基于横坐标之差与纵坐标之差的gcd是1,设横坐标之差是x,纵坐标之差是y:

  • x为0或者y为0,是2 * n * (n-1)对,这就是k=1的时候啦。
  • x,y不为0且最大公约数是1,是2 * (n - x) * ( n - y) 对

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
const LL Mod = 1e9+7;
const int M = 3e5+10;
LL f[N];
int main() {int n = 1000, k = 500;LL ans = 2 * n * (n-1) % Mod;for(int i = 1; i < n; ++i) {for(int j = 1; j < n; ++j) {if(__gcd(i, j) == 1 && i*i+j*j <= k*k) {ans = (ans + 2*(n-i)%Mod*(n-j)%Mod) % Mod;}}}cout << ans % Mod << endl;return 0;
}

答案:916585708

试题 F:寻找重复项(程序设计)

题意:点此进入

做法:用map记录,访问到就值+1

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2e6+10;
const LL Mod = 1e9+7;
const int M = 3e5+10;
LL f[N], a, b, c;
map<LL, int> mp;
int main() {f[0] = 1;++mp[1];scanf("%lld%lld%lld", &a, &b, &c);int flag = 0;_rep(1, 2000000, i) {f[i] = (a*f[i-1]%c + f[i-1]%b)%c;if(mp[f[i]]) { flag = i; break; }++mp[f[i]];}if(!flag) puts("-1");else printf("%d\n", flag);return 0;
}

试题 G:被袭击的村庄(程序设计)

题意:点此进入


做法:这就是一道卡了我一下午的模拟题,水逆的一天,这题不难,就是题目错了…输出的是道路、房屋、田地耐久度降为0的个数。直接模拟就好了,我是少考虑的一个边界情况以及老眼昏花没看见自己判断结果的循环放到while循环里了。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 310;
const LL Mod = 1e9+7;
const int M = 3e5+10;
LL n, m;
LL a, b, c; //三种耐久度
LL k; //炮弹攻击范围k*k
LL w; //溅射伤害
LL q; //q枚炮弹
LL id, x, y;  //炮弹编号,及中心位置
LL sh[N][N]; //炮弹伤害
LL ans;
LL num1, num2, num3;
LL num[N][N];
LL bx, by, ex, ey;
LL hp[N][N];
void caljs(int x, int y) {  //溅射伤害int tx, ty;for(int i = 0; i < 8; ++i) {tx = x + ne[i][0]; ty = y + ne[i][1];if(tx < 1 || ty < 1 || tx > n || ty > m) continue;hp[tx][ty] = max(0ll, hp[tx][ty] - w);}
}
int main() {scanf("%lld%lld%lld%lld%lld%lld%lld", &n, &m, &a, &b, &c, &k, &w);_rep(1, k, i) _rep(1, k, j) scanf("%lld", &sh[i][j]);_rep(1, n, i) _rep(1, m, j) {scanf("%lld", &num[i][j]);if(num[i][j] == 1) hp[i][j] = a;else if(num[i][j] == 2) hp[i][j] = b;else hp[i][j] = c;}scanf("%lld", &q);while(q--) {scanf("%lld%lld%lld", &id, &x, &y);bx = x - k/2, by = y - k/2;  //炸弹范围的起始坐标ex = x + k/2, ey = y + k/2;  //炸弹范围的终止坐标for(int i = bx, ii = 1; i <= ex, ii <= k; ++i, ++ii)for(int j = by, jj = 1; j <= ey, jj <= k; ++j, ++jj) {if(i < 1 || j < 1 || i > n || j > m) continue;if(!id) caljs(i, j); hp[i][j] = max(0ll, hp[i][j]-sh[ii][jj]);}}_rep(1, n, i) _rep(1, m, j) {if(num[i][j] == 1) {if(!hp[i][j]) ++num1;ans += a-hp[i][j];} else if(num[i][j] == 2) {if(!hp[i][j]) ++num2;ans += b-hp[i][j];} else {if(!hp[i][j]) ++num3;ans += c-hp[i][j];}}printf("%lld %lld %lld\n%lld", num1, num2, num3, ans);return 0;
}

试题 H:字符串(程序设计)

题意:点此进入

做法:这一题明显比上一题简单…直接暴力判断就好了,注意下处理的技巧以防超时。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const int INF = 0x3f3f3f3f;
const int N = 2010;
const LL Mod = 1e9+7;
const int M = 3e5+10;
string s, res;
LL a[N];
int main() {int m;cin >> s >> m;int n = s.size();LL mid = 0, mid1, mid2;for(int i = 0; i < n; ++i) mid = (mid * 26 + s[i]-'A') % m;a[n-1] = 1;for(int i = n-2; i >= 0; --i) a[i] = a[i+1] * 26 % m;if(!mid) { puts("0 0"); return 0; }for(int i = 0; i < n; ++i) {for(int j = i+1; j < n; ++j) {mid1 = (s[i]-s[j]) * a[j];mid2 = (s[j]-s[i]) * a[i];if((mid+mid1+mid2+m)%m == 0) {printf("%d %d\n", i+1, j+1); return 0;}}}puts("-1 -1");return 0;
}

试题 I:最短路(程序设计)

题意:点此进入



做法:正向建图跑一遍再反向建图跑一遍最短路就好了,最后把两次dis的和全加起来。

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include<bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const LL INF = 1e18;
const int N = 2e4+10;
const LL Mod = 1e9+7;
const int M = 2e5+10;
struct edge {int u, v; LL w;
}ed[M];
struct xx {int nxt, to; LL w;xx() {}xx(int a, int b, LL c) {nxt = a; to = b; w = c;}
}e[M];
int tot, head[N];
void Add(int u, int v, LL w) {e[++tot] = xx(head[u], v, w);head[u] = tot;
}
LL dis[N]; int vis[N];
priority_queue<pli, vector<pli>, greater<pli> >pq;
int n, m;
void dij() {_rep(1, n, i) dis[i] = INF, vis[i] = 0;dis[1] = 0;while(!pq.empty()) pq.pop();pq.push(make_pair(0ll, 1));int u, v;while(!pq.empty()) {u = pq.top().second; pq.pop();if(vis[u]) continue;vis[u] = 1;for(int i = head[u]; i; i = e[i].nxt) {v = e[i].to;if(dis[v] > dis[u] + e[i].w) {dis[v] = dis[u] + e[i].w;pq.push(make_pair(dis[v], v));}}}
}
int main() {int T; scanf("%d", &T);while(T--) {memset(head, 0, sizeof head); tot = 0;scanf("%d%d", &n, &m);_for(0, m, i) {scanf("%d%d%lld", &ed[i].u, &ed[i].v, &ed[i].w);Add(ed[i].u, ed[i].v, ed[i].w);}LL ans = 0;dij(); _rep(2, n, i) ans += dis[i];memset(head, 0, sizeof head); tot = 0;_for(0, m, i) Add(ed[i].v, ed[i].u, ed[i].w);dij(); _rep(2, n, i) ans += dis[i];printf("%lld\n", ans);}return 0;
}

试题 J:迷宫(程序设计)

题意:点此进入


做法:bfs搜索题,乍看一眼很简单,实际上有点坑。

  • 循环跳传送门

    • 循环跳过程中有障碍
    • 循环跳过程中经过了终点
    • 循环跳过程中经过了起点
  • 起点就是终点
  • 起点或终点就是障碍物

代码

#include  <algorithm>
#include  <iostream>
#include  <cstring>
#include  <vector>
#include  <cstdio>
#include  <queue>
#include  <cmath>
#include  <set>
#include  <map>
#include  <bitset>
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define PI acos(-1)
#define eps 1e-9
#define rint register int
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
using namespace std;
typedef long long LL;
typedef pair<LL, int> pli;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<LL, LL> pll;
typedef pair<double, double> pdd;
typedef map<int, int> mii;
typedef map<LL, int> mli;
typedef map<char, int> mci;
typedef map<string, int> msi;
template<class T>
void read(T &res) {int f = 1; res = 0;char c = getchar();while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }while(c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = getchar(); }res *= f;
}
const int ne[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, -1, -1, -1, 1, 1, -1, 1, 1};
const LL INF = 1e18;
const int N = 1010;
const LL Mod = 1e9+7;
const int M = 110;
int n, m, Q, mid;
char tu[N][N];
int door[N][N], vis[N][N];
pii d[M];
int ex, ey;
struct xx {int x, y, step;
}u;
queue<xx> q;
int check(int tx, int ty) {if(tx < 1 || ty < 1 || tx > n || ty > m ) return 0;if(vis[tx][ty] || tu[tx][ty] != '.') return 0;return 1;
}
int bfs() {int tx = 1, ty = 1;while(door[tx][ty] && !vis[tx][ty] && tu[tx][ty] == '.') {if(tx == ex && ty == ey) return 0;mid = door[tx][ty];vis[tx][ty] = 1; tx = d[mid].first, ty = d[mid].second;if(tx == ex && ty == ey) return 0;}if(!check(tx, ty)) return -1;q.push(xx{tx, ty, 0}); vis[tx][ty] = 1;while(!q.empty()) {u = q.front(); q.pop();if(u.x == ex && u.y == ey) return u.step;for(int i = 0; i < 4; ++i) {tx = u.x + ne[i][0], ty = u.y + ne[i][1];if(!check(tx, ty)) continue;while(door[tx][ty] && !vis[tx][ty] && tu[tx][ty] == '.') {if(tx == ex && ty == ey) return u.step+1;mid = door[tx][ty];vis[tx][ty] = 1; tx = d[mid].first, ty = d[mid].second;if(tx == ex && ty == ey) return u.step+1;}if(!check(tx, ty)) continue;vis[tx][ty] = 1; q.push(xx{tx, ty, u.step+1});}}return -1;
}
int main() {scanf("%d %d", &n, &m);_rep(1, n, i) scanf("%s", tu[i]+1);scanf("%d", &Q);int x, y;_rep(1, Q, i) {scanf("%d%d%d%d", &x, &y, &d[i].first, &d[i].second);door[x][y] = i;}scanf("%d%d", &ex, &ey);int res = bfs();if(res == -1) puts("No solution");else printf("%d\n", res);return 0;
}
/*
3 4
..*.
..*.
..*.
3
2 2 2 4
2 4 3 1
3 1 1 4
1 4
*/

2020蓝桥杯B 组省赛计蒜客模拟赛(一)题解相关推荐

  1. 【计蒜客模拟赛系列】-计蒜客2021年8月普及组模拟赛

    提前:本文中部分代码和思路有借鉴或摘抄计蒜客官方题解 赛后总结 本次模拟赛的难度总算正常了些 个人战绩: 220/400,排名61 ,太弱了,一大堆AK爷 题目质量评价: 题目相比CSP-J还是简单了 ...

  2. 计蒜客模拟赛D1T3 蒜头君的坐骑:用dfs转移dp

    题目链接:https://nanti.jisuanke.com/t/16447 题意: 蒜头君有一只坐骑,人马. 一天,蒜头君骑着他的坐骑走上了一片n*m的大荒野,一开始时,蒜头君在(1,1)点,他要 ...

  3. 计蒜客模拟赛5-礼物盒

    小y 有一个宽度为 100cm,高度为 20cm,深度为 1cm 的柜子,如下图. 小y 还有 36个礼物盒,他们的深度都为 1cm. 他们对应的宽度和高度如下,单位(cm). 11 3 8 12 1 ...

  4. 计蒜客模拟赛7礼品盒

    第七题 小y 有一个宽度为 100cm,高度为 20cm,深度为 1cm 的柜子,如下图. 小y 还有 3636 个礼物盒,他们的深度都为 1cm. 他们对应的宽度和高度如下,单位(cm). 现在小y ...

  5. 第十三届蓝桥杯(Web 应用开发)线上模拟赛第一题

    [Bug 调试]修复网站显示问题 特别说明 第十三届蓝桥杯(Web 应用开发)线上模拟赛依托于蓝桥云课线上实验环境打造,可能与正式比赛所使用线下环境有所不同.线上模拟赛侧重于考生了解比赛题型和体验比赛 ...

  6. 计蒜客超级书架2题解

    题目链接: https://nanti.jisuanke.com/t/T1736 首先这道题是一道典型的DFS题.我们需要用DFS枚举最小距离,就行了. 首先需要头文件和定义: #include< ...

  7. 【解题报告】2020蓝桥杯B组模拟 计蒜客 结果填空:苹果

    问题描述 有 3030 个篮子,每个篮子里有若干个苹果,篮子里的苹果数序列已经给出. 现在要把苹果分给小朋友们,每个小朋友要么从一个篮子里拿三个苹果,要么从相邻的三个篮子里各拿一个苹果. 苹果可以剩余 ...

  8. 2020蓝桥杯C-B组模拟赛—有趣的数字

    我们称一个数是质数,而且数位中出现了 5 的数字是有趣的.例如 5, 59, 457都是有趣的,而 15, 7不是.求 1 到 100000 中有趣的数的个数. #include<stdio.h ...

  9. 第十三届蓝桥杯(Web 应用开发)线上模拟赛【第三题】(封装函数实现个人所得税计算器)

    考试需求 基于挑战提供的基础代码,完善个人所得税计算器结构,实现当用户在文本框中输入薪资后,单击计算按钮,即可将计算后的结果显示到页面中. 例如: 当输入 5000,根据个人所得税规则无需缴税,页面效 ...

最新文章

  1. html5手机端设置date,如何在移动端更好地使用HTML5 date input
  2. linux sersync2 ssh start=true,rsync+nfs+sersync实战案例
  3. Nature会议:驾驭植物微生物组(21年10月22-24,在线,优惠截止9月24日)
  4. Hystrix配置参数查找方式
  5. r语言中mpg数据_R语言常用的数据处理的包(1)
  6. ubuntu 12下的apache+php+mysql_老司机传授Ubuntu下Apache+PHP+MySQL环境搭建攻略
  7. 支付宝支付php代码示例,Laravel使用支付宝进行支付的示例代码
  8. py2exe使用方法 (含一些调试技巧,如压缩email 类)
  9. Android studio3.2学习开发JNI并且生成so库教程
  10. 电源大师课笔记 2.8
  11. (二)NI采集卡应用学习:使用NI MAX创建测量任务及常见错误
  12. 最近学习金融知识的感悟
  13. Notepad++ 无法安装 HexEditor 插件 / 安装之后闪退
  14. SuperMap BIM+GIS-Revit模型处理-背景
  15. 乐优商城之规格参数商品查询(十)
  16. 瑞星2005升级问题汇总
  17. wpf修改鼠标悬停效果
  18. 【企业数字化转型】网络协同和数据智能双螺旋驱动——活数据:流动创造价值...
  19. Java用i74G的显卡_【省钱日记】第5期,二手RX560 4G显卡+老i7,实测体验分享
  20. Vue中动态加载SVG文件并绑定事件、修改节点数据

热门文章

  1. 夜光祝愿大家 520 快乐
  2. bat文件启动uipath机器人
  3. 【漏洞复现】永恒之蓝漏洞(MS17-010)
  4. python解释器安装,pycharm安装
  5. 如何安装MySQL Workbench(超简单)
  6. React Native集成CodePush热更新
  7. 【蓝桥杯选拔赛真题28】python字符串包含字符 青少年组蓝桥杯python 选拔赛STEMA比赛真题解析
  8. 漂亮动画效果的Dialog--NiftyDialogEffects
  9. 从零学SpringCloud系列(八):分布式配置中心Spring Cloud Config
  10. 在线软件测试平台,免费好用的APP安全在线检测平台