基础题单
没有递交 | - | A1329 【例8.2】细胞 |
没有递交 | - | P1596 [USACO10OCT] Lake Counting S |
没有递交 | - | A1250 The Castle |
没有递交 | - | A1492 山峰和山谷 |
没有递交 | - | A1252 走迷宫 |
没有递交 | - | A1255 迷宫问题 |
没有递交 | - | A1253 抓住那头牛 |
没有递交 | - | A1360 奇怪的电梯(lift) |
没有递交 | - | A1216 红与黑 |
没有递交 | - | A1215 迷宫 |
没有递交 | - | A1213 八皇后问题 |
没有递交 | - | A1318 【例5.3】自然数的拆分 |
没有递交 | - | A1317 【例5.2】组合的输出 |
没有递交 | - | P1706 全排列问题 |
没有递交 | - | A1473 素数环 |
没有递交 | - | B3622 枚举子集 |
没有递交 | - | A1219 马走日 |
没有递交 | - | A1220 单词接龙 |
没有递交 | - | A1221 分成互质组 |
没有递交 | - | A1474 矩阵距离 |
1250:The Castle
//BFS模板题,直接用的双端队列dequeue
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2E2+10, step_num=4;//八个方向模板,前四个是十字方向需要时改下step_num=4
int n,m,cnt=0,max_size=0, steps[8][3]={{0,1,4},{0,-1,1},{1,0,8},{-1,0,2},{1,1},{1,-1},{-1,1},{-1,-1}};//steps[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
bool vis[maxn][maxn];
int d[maxn][maxn];
int map[maxn][maxn];
struct node{
int x,y;
node (int a, int b){
x=a;
y=b;
}
};
deque<node> q;
void bfs(int x, int y){
int ret=1;
node t=node(x,y);
q.push_front(t);
vis[t.x][t.y]=true;
while(!q.empty()){
t=q.front();
q.pop_front();
for(int i=0;i<step_num;i++){
node nxt=node(t.x+steps[i][0],t.y+steps[i][1]);
if(nxt.x>=0&&nxt.x<n&&nxt.y>=0&&nxt.y<m&&!vis[nxt.x][nxt.y]&&(d[t.x][t.y]&steps[i][2])==0){
//本来想另开数组处理地图的,但就对着temp当前点处理墙判断联通就行了啊啊啊,直接二进制按位与
q.push_front(nxt);
vis[nxt.x][nxt.y]=true;
ret++;
}
}
}
max_size=max(max_size,ret);
}
int main(){
memset(vis, 0, sizeof(vis));
// memset(map, 0, sizeof(map));
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>d[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(vis[i][j]){
continue;
}
bfs(i,j);
cnt++;
}
}
cout<<cnt<<endl<<max_size;
return 0;
}
烦烦烦
1454:山峰和山谷
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1E3+10, step_num=8;//八个方向模板,前四个是十字方向需要时改下step_num=4
int n,m,cnt_low=0,cnt_high=0, steps[8][3]={{0,1,4},{0,-1,1},{1,0,8},{-1,0,2},{1,1},{1,-1},{-1,1},{-1,-1}};//steps[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
bool vis[maxn][maxn], is_low=true, is_high=true;
int d[maxn][maxn];
struct node{
int x,y;
node (int a, int b){
x=a;
y=b;
}
};
deque<node> q;
void bfs(int x, int y){
is_low=true, is_high=true;
node t=node(x,y);
q.push_front(t);
vis[t.x][t.y]=true;
while(!q.empty()){
t=q.front();
q.pop_front();
for(int i=0;i<step_num;i++){
node nxt=node(t.x+steps[i][0],t.y+steps[i][1]);
if(nxt.x>=0&&nxt.x<n&&nxt.y>=0&&nxt.y<n){
if(d[nxt.x][nxt.y]>d[t.x][t.y]){
is_high=false;//点t不可能是最高峰了
}
if(d[nxt.x][nxt.y]<d[t.x][t.y]){
is_low=false;//点t不可能是最低峰了
}
if(!vis[nxt.x][nxt.y]&&d[nxt.x][nxt.y]==d[t.x][t.y]){//再联通点nxt
q.push_front(nxt);
vis[nxt.x][nxt.y]=true;
}
}
}
}
if(is_high) cnt_high++;
if(is_low) cnt_low++;
}
int main(){
memset(vis, 0, sizeof(vis));
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin>>d[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(vis[i][j]){
continue;
}
bfs(i,j);
}
}
cout<<cnt_high<<" "<<cnt_low;
return 0;
}