A. Save Energy!

本文介绍了一个烹饪鸡的时间计算问题,考虑到炉子会在特定时间内自动关闭并由Julia定期重启。文章提供了一种解决该问题的有效算法,并通过两个例子展示了如何计算烹饪所需的确切时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after kminutes after turning on.

During cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.

It is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.

Input

The single line contains three integers kd and t (1 ≤ k, d, t ≤ 1018).

Output

Print a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10 - 9.

Namely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if .

Examples
input
Copy
3 2 6
output
6.5
input
Copy
4 2 20
output
20.0
Note

In the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for . Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for . Thus, after four minutes the chicken will be cooked for . Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready .

In the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.

本来的思路写法因为精度问题,有的样例过不了,看了博客思路很腻害

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll k,d,t,T;
    while(~scanf("%lld%lld%lld",&k,&d,&t))
    {
        T=k+(k%d==0? 0:(k/d+1)*d-k);//周期长度
        double T1=k+(T-k)*0.5;//根据成熟度求得的周期
        ll num=t/T1;//需要num个周期能熟。
        double ans=num*T;//小于等于t的周期的最大倍数
        double st=t-num*T1;//还不熟部分
        //处理不熟部分
        if(st<k) ans+=st;
        else ans+=(k+(st-k)*2);
        printf("%.1lf\n",ans);
    }
}

``` /clear,start/filname,GEARANALYSIS,1!\−原有几何建模部分保持不变 !===============瞬态分析设置补充================= /SOLU ANTYPE,4 !瞬态分析类型 TRNOPT,FULL !使用完全瞬态算法 NLGEOM,ON !考虑几何非线性 TIME,1 !总计算时间1秒 DELTIM,0.01,0.005,0.02 !初始时间步0.01,最小0.005,最大0.02秒 KBC,0 !渐变载荷施加方式 AUTOTS,ON !自动时间步长 OUTRES,ERESX,10 !每个子步存储结果 OUTRES,ALL,20 !每20子步存储所有结果 !设置阻尼参数 ALPHAD,0.02 !质量阻尼系数 BETAD,0.003 !刚度阻尼系数 !定义约束条件 NSEL,S,LOC,X,0D,ALL,UX,0,,,,UY,UZ!约束中心节点自由度 ALLSEL SOLVE!开始求解 SAVE!保存数据库 FINISH !=================后处理设置================= /POST26 NUMVAR,200!增加变量存储空间 !定义摩擦力量测变量 ESOL,2,CONTACT ELEMENT NUM,1,SMISC,31,F FRICTION X!X方向摩擦力ESOL,3,CONTACT ELEMENT NUM,1,SMISC,32,F FRICTION Y!Y方向摩擦力ESOL,4,CONTACT ELEMENT NUM,1,SMISC,33,F FRICTION Z ​ !Z方向摩擦力VECT,5,2,3,4!合成摩擦力矢量PROD,6,5,5!计算摩擦力模值平方SQRT,7,6,,,F F ​ RICTION M ​ AG!合成摩擦力模值!定义能量变量ETABLE,EFRICT,SMISC,34!摩擦耗散能ETABLE,EWORK,SMISC,35!接触做功SSUM!求和接触单元能量∗GET,ENERGY F ​ RICTION,SSUM,,ITEM,EFRICT∗GET,ENERGY W ​ ORK,SSUM,,ITEM,EWORK!时间历程绘图PLVAR,7!绘制摩擦力时程曲线XVAR,1!X轴为时间PLVAR,ENERGY F ​ RICTION,ENERGY W ​ ORK!绘制能量曲线!生成能量报告PRVAR,ENERGY F ​ RICTION,ENERGY W ​ ORK∗CFOPEN,ENERGY R ​ EPORT,TXT∗VWRITE, ′ 总摩擦耗散能(J): ′ ,ENERGY F ​ RICTION(F10.0,A,F15.6)∗VWRITE, ′ 总接触功(J): ′ ,ENERGY W ​ ORK(F10.0,A,F15.6)∗CFCLOS!动画生成/ANIMATE,SWEEP,,,5ANDATA,0.5,,,0,10,1,0,0.2ANCNTR,10,0.1!```把这段代码重新整理一下,加注释,内容不用变
最新发布
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值