B - Save Energy! CodeForces - 936A

题目链接:https://vjudge.net/problem/CodeForces-936A

按照题意模拟即可 我的做法是首先求出d的多少倍可以完全覆盖k 然后把这个看作一个周期 算一下周期内对食物能够烤熟百分之多少 然后看一下总共有几个这样的循环 最后处理一下结尾 讨论一下即可,结尾讨论一下剩余的火力和k的大小。

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#define LL long long
using namespace std;
int main()
{
	LL on,look,Time;
	double ans=0;
	LL i,tmp;
	scanf("%lld%lld%lld",&on,&look,&Time);
	if(on>=Time)
	{
		ans=Time;
	}
	else{
		
		for(i=look;;i+=look)
		{
			if(i>=on) 
			{
				tmp = i;
				break;
			}
		}
		//cout<<tmp<<endl;
		double half_fire = (tmp-on)*0.5;
		double circle_fire = on+half_fire;
		LL one = Time/circle_fire;
		ans+=one*tmp;
	
		double sheng = Time-one*circle_fire;
		if(sheng<=on) ans+=sheng;
		else{
			ans+=sheng;
			ans+=(sheng-on)*0.5;
		}
	}
	printf("%.1lf\n",ans);
	return 0;
	
}

猜你喜欢

转载自blog.csdn.net/qq_40816078/article/details/89714229