求助
查看原帖
求助
724221
ILoveSoviet楼主2022/10/23 11:34

传送门 P1095
这是我的代码:

#include<iostream>
#include<queue>
#include<limits.h>
#define YY "Yes"
#define NN "No"
using namespace std;
void bfs(int,int,int,int);
int main(){
	ios_base::sync_with_stdio(false);
	int m,s,t;
	cin>>m>>s>>t;
	if(t*10<m){
		if(t*60>s){
			cout<<"Yes\n"<<s/60+1;
			return 0;
		}
		else{
			cout<<"No\n"<<t*60;
			return 0;
		}
	}
	else{
		int size_of_now=0,g=0;
		while(m>=10){
			m-=10;
			t--;
			s-=60;
			g++;
		}
		bfs(m,s,t,g);
	}
}
struct node{
	int index,size,mfz;
};
queue<node> a;
void bfs(int m,int s,int t,int g){
	ios_base::sync_with_stdio(false);
	node ne;
	ne.index=0;
	ne.size=0;
	ne.mfz=m;
	a.push(ne);
	int mi=INT_MAX,ma=0;
	while(!a.empty()){
		ne=a.front();
		a.pop();
		ma=max(ma,ne.size);
//		cout<<ne.index<<" "<<ne.mfz<<" "<<ne.size<<endl;
		if(ne.size>=s){
			mi=min(mi,ne.index);
			break;
		}
		else if(ne.index>=t)	continue;
		node b=ne;
		b.index++;
		b.size+=17;
		a.push(b);
		b=ne;
		b.index++;
		b.mfz+=4;
		a.push(b);
		if(ne.mfz>=10){
			b=ne;
			b.index++;
			b.size+=60;
			b.mfz-=10;
			a.push(b);
		}
	}
	if(mi!=INT_MAX)	cout<<YY<<"\n"<<mi+g;
	else			cout<<NN<<"\n"<<ma+g;
} 

大体的思路是先贪心再搜索,但是一直只有四十分

2022/10/23 11:34
加载中...