暑假刷题第21天--8/4

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
#include
#include
using namespace std;
const int N=200005;
void solve(){
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	vectorq(n,-1),w(n,n);
	for(int i=0;i0)q[i]=q[i-1];
		if(s[i]=='0')q[i]=i;
	}
	for(int i=n-1;i>=0;i--){
		if(i >ans;
	while(m--){
		int l,r;
		cin>>l>>r;
		l--,r--;
		if(w[l]>q[r]){
			ans.insert({-1,-1});
		}
		else {
			ans.insert({w[l],q[r]});
		}
	}
	cout<>t;
	while(t--){
		solve();
	}
}

Problem - D - Codeforces(思维)

#include
#include
#include
#include
#include
#include
using namespace std;
const int N=200005;
int a[N],b[N];
bool vis[N];
void solve(){
	int n;
	cin>>n;
	for(int i=0;i>a[i];
	}
	int res=0,res2=0;
	for(int i=0;i=0;j--){
				vis[j]=true;
				if(a[j]==0){
					break;
				}
			}
			for(int j=i+1;j0&&!vis[i-1]){
				vis[i-1]=true;
				p=1;
			}
			for(int j=i+1;j>t;
	while(t--){
		solve();
	}
}

4443. 无限区域 - AcWing题库(模拟)

#include
#include
#include
#include
#include
#include
using namespace std;
const int N=200005;
double p=3.1415926;
int cnt=0;
void solve(){
	long long r,a,b;
	cnt++;
	cin>>r>>a>>b;
	double ans=0;
	int f=0;
	while(r!=0){
		ans+=r*r*p;
		if(f==0)r=r*a,f=1;
		else r=r/b,f=0;
	}
	printf("Case #%d: %.6lf\n",cnt,ans);
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
}

你可能感兴趣的:(暑假打卡,算法,图论,深度优先)