P1902 刺杀大使 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)(优先队列bfs/二分答案+bfs)
#include
#include
using namespace std;
int n,m;
const int N=1005;
int a[N][N];
int cnt[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
bool vis[N][N];
struct node{
int step,xx,yy;
bool operator<(const node &xx)const
{
return xx.step=n||y>=m)return 0;
return 1;
}
int bfs(){
priority_queueq;
node c;
c.step=0,c.xx=0,c.yy=0;
q.push(c);
vis[0][0]=true;
while(!q.empty()){
node t=q.top();
q.pop();
if(t.xx==n-1&&t.yy==m-1)return t.step;
for(int i=0;i<4;i++){
int tx=t.xx+cnt[i][0];
int ty=t.yy+cnt[i][1];
if(in(tx,ty)&&!vis[tx][ty]){
node now;
now.xx=tx,now.yy=ty,now.step=max(t.step,a[tx][ty]);
q.push(now);
vis[tx][ty]=true;
}
}
}
return 0;
}
int main(){
cin>>n>>m;
for(int i=0;i>a[i][j];
}
}
cout<
#include
#include
#include
using namespace std;
int n,m;
const int N=1005;
int a[N][N];
int cnt[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
bool vis[N][N];
struct node{
int xx,yy;
};
int in(int x,int y){
if(x<0||y<0||x>=n||y>=m)return 0;
return 1;
}
int bfs(int x){
queueq;
memset(vis,0,sizeof(vis));
node c;
c.xx=0,c.yy=0;
q.push(c);
vis[0][0]=true;
while(!q.empty()){
node t=q.front();
q.pop();
if(t.xx==n-1)return 1;
for(int i=0;i<4;i++){
int tx=t.xx+cnt[i][0];
int ty=t.yy+cnt[i][1];
if(in(tx,ty)&&!vis[tx][ty]&&a[tx][ty]<=x){
node now;
now.xx=tx,now.yy=ty;
q.push(now);
vis[tx][ty]=true;
}
}
}
return 0;
}
int main(){
cin>>n>>m;
int l=0,r=0;
for(int i=0;i>a[i][j];
r=max(r,a[i][j]);
}
}
while(r>l){
int mid=(r+l)/2;
if(bfs(mid)){
r=mid;
}
else l=mid+1;
}
cout<
Problem - A - Codeforces(签到)
#include
using namespace std;
void solve(){
int a,b,c;
cin>>a>>b>>c;
if(a>b+c){
cout<<2*(b+c)+1<>t;
while(t--){
solve();
}
}
Problem - B - Codeforces(优先队列--需熟练掌握重载运算)
#include
#include
using namespace std;
struct node{
int x,y;
};
bool operator<(const node &a,const node &b)
{
if(a.x!=b.x)return a.xb.y;
}
void solve(){
int n,k;
cin>>n>>k;
priority_queueq;
for(int i=0;i>x.x;
x.y=i;
q.push(x);
}
while(!q.empty()){
node t=q.top();
q.pop();
if(t.x<=k){
cout<>t;
while(t--){
solve();
}
}
Problem - C - Codeforces(思维)
#include
#include
#include
#include
Problem - D - Codeforces(思维)
#include
#include
#include
#include
4443. 无限区域 - AcWing题库(模拟)
#include
#include
#include
#include