华为-洞穴逃生(OJ通过)

// 贪心算法,关键在贪心决策
#include <iostream>
#include <string>
using namespace std;

const int speed_len = 17;
const int move_len = 60;
const int basic_m = 10;
const int rest_m = 4;
const string s_yes = "Yes ";
const string s_no = "No ";

void get_t(int &M,int &time,int &length)
{
	int t = 1;
	while(1){
		int len_move = 0;
		int m=M;
		for(int i=1; i<=t; ++i){
			if(m >= basic_m){
				len_move += move_len;
				m -= basic_m;
			}
			else
				m += rest_m;
		}
		if( len_move >= t*speed_len ){
			time = t;
			length = len_move;
			M = m;
			return;
		}
		t++;
	}
}

void escape(int M,int S,int T)
{
	int max_len = 0;
	int basic_t = T;
	while( M>=10 && T>0 ){
		max_len += move_len;
		M -= 10;
		T -= 1;
		if(max_len >= S){
			cout<<s_yes<<(basic_t - T)<<endl;
			return;
		}
	}
	S -= max_len;
	while(1){
		int time ,length;
		get_t(M,time,length);
		//cout<<time<<" "<<length<<endl;
		if(time > T){
			if( (S+speed_len-1)/speed_len > T){
				max_len += T*speed_len;
				cout<<s_no<<max_len<<endl;
				return;
			}
			else{
				T -= (S+speed_len-1)/speed_len;
				cout<<s_yes<<(basic_t -T)<<endl;
				return;
			}

		}
		else{
			if( S > length){
				S -= length;
				max_len += length;
				T -= time;
			}
			else {
				int t_min = min((S+speed_len-1)/speed_len, time);
				T -= t_min;
				cout<<s_yes<<(basic_t -T)<<endl;
				return;
			}
		}
	}
}
int main()
{
	int M,S,T;
	int max_len;
	while(cin>>M>>S>>T){
		if(S == 0){
			cout<<s_yes<<0<<endl;
			continue;
		}
		if(T == 0){
			cout<<s_no<<0<<endl;
			continue;
		}
		escape(M,S,T);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值