0%

3.9

[蓝桥杯2017初赛]迷宫

题目描述
X星球的一处迷宫游乐场建在某个小山坡上。它是由10x10相互连通的小房间组成的。
房间的地板上写着一个很大的字母。我们假设玩家是面朝上坡的方向站立,则:
L表示走到左边的房间,R表示走到右边的房间,U表示走到上坡方向的房间,D表示走到下坡方向的房间。
X星球的居民有点懒,不愿意费力思考。他们更喜欢玩运气类的游戏。这个游戏也是如此!
开始的时候,直升机把100名玩家放入一个个小房间内。玩家一定要按照地上的字母移动。

迷宫地图如下:

UDDLUULRUL
UURLLLRRRU
RRUURLDLRD
RUDDDDUUUU
URUDLLRRUU
DURLRLDLRL
ULLURLLRDU
RDLULLRDDD
UUDDUDUDLL

ULRDLUURRR

请你计算一下,最后,有多少玩家会走出迷宫? 而不是在里边兜圈子。
输出
输出一个整数表示答案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e6+5;

char mat[15][15];
bool vis[15][15];
int ans=0;


void dfs(int x,int y){
if(x<1||x>10||y<1||y>10){
ans++;
return ;
}
char ch=mat[x][y];
if(ch=='U'&&!vis[x-1][y]){
vis[x-1][y]=1;
dfs(x-1,y);
vis[x-1][y]=0;
}
if(ch=='D'&&!vis[x+1][y]){
vis[x+1][y]=1;
dfs(x+1,y);
vis[x+1][y]=0;
}
if(ch=='R'&&!vis[x][y+1]){
vis[x][y+1]=1;
dfs(x,y+1);
vis[x][y+1]=0;
}
if(ch=='L'&&!vis[x][y-1]){
vis[x][y-1]=1;
dfs(x,y-1);
vis[x][y-1]=0;
}
}



int main (){
/*char s;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
scanf(" %c",&s);
mat[i][j]=s;
}
}


for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
vis[i][j]=1;
dfs(i,j);
vis[i][j]=0;
}
}
printf("%d\n",ans);*/
cout<<31<<endl;

return 0;
}

[蓝桥杯2018初赛]分数

题目描述
1/1 + 1/2 + 1/4 + 1/8 + 1/16 + ….
每项是前一项的一半,如果一共有20项,求这个和是多少,结果用分数表示出来。
类似:3/2当然,这只是加了前2项而已。分子分母要求互质。

输出
按格式输出答案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e6+5;

int main (){
ll a=0;
for(int i=0;i<=19;i++){
a+=1<<i;
}
ll b=1<<19;
ll c=__gcd(a,b);
a/=c;
b/=c;
cout<<a<<"/"<<b<<endl;
return 0;
}
-------------本文结束感谢您的阅读-------------