首页 > 试题广场 >

独立的小易

[编程题]独立的小易
  • 热度指数:1524 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
小易为了向他的父母表现他已经长大独立了,他决定搬出去自己居住一段时间。一个人生活增加了许多花费: 小易每天必须吃一个水果并且需要每天支付x元的房屋租金。当前小易手中已经有f个水果和d元钱,小易也能去商店购买一些水果,商店每个水果售卖p元。小易为了表现他独立生活的能力,希望能独立生活的时间越长越好,小易希望你来帮他计算一下他最多能独立生活多少天。

输入描述:
输入包括一行,四个整数x, f, d, p(1 ≤ x,f,d,p ≤ 2 * 10^9),以空格分割


输出描述:
输出一个整数, 表示小易最多能独立生活多少天。
示例1

输入

3 5 100 10

输出

11
def live_alone(x, f, d, p):
    if f >= d/x:
        print (int(d/x))
    else:
        print (int((d+f*p)//(x+p)))
    
x,f,d,p = input().split()
live_alone(float(x), float(f), float(d), float(p))

# 牵涉到精确除法问题

发表于 2018-08-11 12:09:14 回复(0)
#include<iostream>
using namespace std;
int live_day(int x,int f,int d,int p){
    int temp=d/x;
    int day=0;
    if(f>temp)
        return temp;
    else
        day=f+(d-(x*f))/(p+x);
        return day;
           
}
int main(){
    int x;int f;int d;int p;
    cin>>x>>f>>d>>p;
    cout<<live_day(x,f,d,p)<<endl;
    return 0;
}

编辑于 2019-08-02 10:29:43 回复(0)
def surive(x,f,d,p):
    day=0
    while f>=1 and d>=x:
        d-=x
        f-=1
        day+=1
        if f==0:
            d-=p
            f+=1
    return day
本题要点在于,只有满足水果>=1,剩余钱>=每日房租,才能继续活下去1天,当成末日生存来想就好懂多了😉 顶我上去,兄弟萌😘

发表于 2020-12-21 16:33:30 回复(0)
x, f, d, p = map(int, input().split())
if f*x < d:
    # 如果钱够付f天房租
    days = f              # 先把库存水果吃了
    # 再累减每日消费
    d -= f*x
    days += d // (p + x)
    print(days)
else:
    # 否则能交几天房租就能独立几天
    print(d // x)

发表于 2020-12-17 11:45:05 回复(0)
#include<iostream>
using namespace std;
int main()
{
    int x,f,d,p;
    int res=0;
    cin>>x>>f>>d>>p;
    if (d<=f*x)
        res=d/x;
    else
        res=(d-f*x)/(x+p)+f;
    cout<<res;
}

发表于 2020-06-15 11:49:32 回复(0)
x,f,d,p=map(int,input().split())
if d//x>f:
    d=d-f*x
    i=d//(x+p)+f
else:
    i=d//x
print(i) 

编辑于 2018-09-05 15:13:45 回复(0)
import sys
line = sys.stdin.readline().split(' ')
lines = map(lambda x:int(x.strip('/n')),line)
x = lines[0]
f = lines[1]
d = lines[2]
p = lines[3]
if d//x <= f:
    print d//x
else:
    d = d - f * x
    print f + d//(x+p) 
发表于 2018-08-11 11:43:05 回复(0)
[x, f, d, p]=list(map(int,input().split()))
#如果钱不够交房租
if d<x:
    print(0)
#没水果钱不够
elif f==0 and d<x+p:
    print(0)
#水果大于房租天数
elif f>=d//x:
    print(d//x)
#水果小于房租天数
elif f<d//x:
    print((d+p*f)//(x+p))

发表于 2019-09-16 15:16:37 回复(0)
deflive_alone(x, f, d, p):
    iff >=d/x: # f天内不够付房租
        print(int(d/x))
    else: # f天内足够放房租,瓶颈在于剩余资金
        print(int(f+(d-f*x)//(p+x)))
     
x,f,d,p =input().split()
live_alone(float(x), float(f), float(d), float(p))
发表于 2020-06-13 10:04:16 回复(0)
s = input()
s = s.split('')
s = [int(x) for x in s]
if s[1] < s[2]/s[0]:
    print(s[1] + int((s[2]-s[0]*s[1])/(s[0]+s[3])))
else:
    print(int(s[2]/s[0])

发表于 2020-03-19 17:20:24 回复(0)
#include <stdio.h>
intmain()
{
    intx,f,d,p;
    scanf("%d%d%d%d",&x,&f,&d,&p);
    if(x*f>=d) printf("%d\n",d/x);
    elseprintf("%d\n",(d-f*x)/(p+x)+f);
}

发表于 2019-07-31 18:57:38 回复(0)
//只需要考虑是先花完钱还是先吃完水果即可
importjava.util.*;
 
 
publicclassMain {
 
    publicstaticvoidmain(String[] args) {
        Scanner sc=newScanner(System.in);
        intrent=sc.nextInt();
        intnum_fruit=sc.nextInt();
        intmoney=sc.nextInt();
        intcost_fruit=sc.nextInt();
        System.out.println(judge(rent,num_fruit,money,cost_fruit));
         
    }  
     
     
    publicstaticlongjudge(longrent,longnum_fruit,longmoney,longcost_fruit) {
        //先考虑钱用尽之前是否吃完了水果
        if(money/rent<=num_fruit)
            returnmoney/rent;
        else{
            return(money+num_fruit*cost_fruit)/(rent+cost_fruit);
        }
    }  
}

发表于 2019-07-22 14:25:44 回复(0)
int main()
{
int x,f,d,p;
cin>>x,f,d,p;
int day;
if(f>=d/x){
day=d/x;
}
else
{
day=(fp+d)/(x+f);
}
cout>>day>>endl;
return 0;
}
编辑于 2018-08-11 13:12:53 回复(0)
n=1.0
x,f,d,p=raw_input().split()
x=int(x);f=int(f);d=int(d);p=int(p);
if d/x<=f:
    print d/x
else:
    n=(d+f*p)/(x+p)
    print int(n)
发表于 2018-08-10 14:35:06 回复(0)