#include<iostream>#include<queue>usingnamespace std;int n =30, m =50;char g[35][55];bool st[35][55];int dx[4]={1,0,0,-1};int dy[4]={0,-1,1,0};structnode{int x, y, step;
string s;}t, p;
queue<node> q;
string dr ="DLRU";
string bfs(){
p ={0,0,0,""};
q.push(p);
st[0][0]=true;while(q.size()){
t = q.front();
q.pop();if(t.x == n -1&& t.y == m -1)return t.s;for(int i =0; i <4; i ++){int x = t.x + dx[i], y = t.y + dy[i];if(x <0|| x >= n || y <0|| y >= m)continue;if(g[x][y]=='1')continue;if(st[x][y])continue;// printf("%d %d\n", x, y);
p ={x, y, t.step +1, t.s + dr[i]};
q.push(p);
st[x][y]=true;}}}intmain(){// 请在此输入您的代码for(int i =0; i < n; i ++)scanf("%s", g[i]);
cout <<bfs()<< endl;return0;}
B组
蛇形填数
#include<iostream>usingnamespace std;intmain(){// 请在此输入您的代码int dx[4]={0,1,1,-1};int dy[4]={1,-1,0,1};int r =1, c =1, t =1, d =0;while(r !=20|| c !=20){if(d ==0){
r = r + dx[d];
c = c + dy[d];
t ++;}elseif(d ==1){while(c >=2){
r = r + dx[d];
c = c + dy[d];
t ++;if(r ==20&& c ==20){
cout << t << endl;return0;}}}elseif(d ==2){
r = r + dx[d];
c = c + dy[d];
t ++;}else{while(r >=2){
r = r + dx[d];
c = c + dy[d];
t ++;if(r ==20&& c ==20){
cout << t << endl;return0;}}}
d =(d +1)%4;}return0;}
跑步锻炼
#include<iostream>usingnamespace std;int months[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};boolis_leap(int y,int m){if(m !=2)returnfalse;return(y %4==0&& y %100!=0)|| y %400==0;}boolcheck(int y,int m,int d){if(m <1|| m >12)returnfalse;if(d <1|| d > months[m]+is_leap(y, m))returnfalse;returntrue;}intmain(){// 请在此输入您的代码int sum =0, w =5;for(int i =20000101; i <=20201001; i ++){int y = i /10000, m = i %10000/100, d = i %100;if(check(y, m, d)){if(d ==1|| w +1==1) sum +=2;else sum +=1;
w =(w +1)%7;}}
cout << sum << endl;return0;}
C组
卡片
#include<iostream>usingnamespace std;int a[10];boolcheck(int x){while(x){if(--a[x %10]<0)returnfalse;
x /=10;}returntrue;}intmain(){// 请在此输入您的代码int i;for(i =0; i <=9; i ++) a[i]=2021;for(i =1; i; i ++){if(!check(i))break;}
cout << i -1<< endl;return0;}
相乘
#include<iostream>usingnamespace std;constint N =1000000007;intmain(){// 请在此输入您的代码longlong a =2021;for(int i =1000000007; i; i --){if(a * i % N ==999999999){
cout << i << endl;return0;}}return0;}
#include<iostream>usingnamespace std;constint N =1000000007;intmain(){// 请在此输入您的代码
cout <<17812964<< endl;return0;}