5 条题解
-
0
python如有更好解法,请讨论
# 2-5获取预算,放入budget budget = [] for i in range(12): a = int(input()) budget.append(a) mom = 300 # 每个月妈妈会给300 total = 0 # 存了多少钱 flag = 1 for i in range(12): money = mom - budget[i] # 可用金额减去预算为剩下的钱 if money < 0: # 预算不足 money = 0 # 剩余的钱为0 flag = -(i+1) print(flag) break else: # 预算充足 if money / 100 >= 1: # 查看是否有整百的钱 num = (money//100)*100 # 有多少整百的钱 total = total + num # 整百的钱存放到total money = money - num # 存完钱后剩余的钱 mom = 300 + money # 下个月的可用金额为妈妈给的300+上个月剩余的钱 else: # 没有整百的钱 mom = 300 + money # 下个月的可用金额为妈妈给的300+上个月剩余的钱 if flag>0: print(int(total+(total*0.2)+money))
-
0
#include<iostream> using namespace std; int money, cost, mama, flag = 1, monthofdeath; int main() { for(int i = 1; i <= 12; i++) { money += 300; cin >> cost; money -= cost; if(money < 0) { flag = 0; monthofdeath = i; break; } mama += money / 100; money %= 100; } if(flag == 1) { money += mama * 120; cout << money; } else cout << -monthofdeath; return 0; }
-
0
「NOIP2004」津津的储蓄计划 题解
题目传送门
欢迎大家指出错误并联系这个蒟蒻
更新日志
- 2023-04-04 21:13 完成了文章
题目知识点
模拟
题目分析
非常的“明显”,这是一道模拟题。
题意说明
有可能在某个月的月初,津津手中的钱加上这个月妈妈给的钱(津津可以随时把整百的钱存在她那里,到了年末她会加上20%还给津津),不够这个月的原定预算(每个月的月初,在得 到妈妈给的零花钱后,如果她预计到这个月的月末手中还会有多于100元或恰好100元,她就会把整百的钱存在妈妈那里,剩余的钱留在自己手中),判断会不会出现这种情况。如果不会,计算到2004年年末,妈妈将津津平常存的钱加上20%还给津津之后,津津手中会有多少钱。(
存钱是个好习惯)代码+解释
#include<bits/stdc++.h>//伟大的万能头文件 using namespace std; int a[12],moneyma=0,moneyjin=0;//moneyma表示现在存在妈妈那里的钱,moneyjin表示津津手里的钱,要记得先清零 int main() { for(int i=0;i<=11;i++) { cin>>a[i];//输入每个月的预算 } for(int i=0;i<=11;i++) { moneyma=((moneyjin+300-a[i])/100)*100+moneyma;//计算存在妈妈的钱 moneyjin=(moneyjin+300-a[i])-(moneyjin+300-a[i])/100*100;//计算手里的钱 if(moneyjin<0)//考虑到不够用的情况 { cout<<"-"<<i+1; return 0; } } //防抄袭 cout<<moneyma*1.2+moneyjin<<endl;//按要求计算并输出 return 0;//华丽结束 }
-
-1
#include<iostream> #include<cstdio> using namespace std; int a[13],mom,mine,b; int main(){ for(int i=1;i<=12;++i)scanf("%d",&a[i]); for(int i=1;i<=12;++i){ mine+=300-a[i]; if(mine<0){ printf("-%d\n",i); return 0; } mom+=(mine/100)*100; mine%=100; }mine+=mom*1.2; printf("%d\n",mine); return 0; }
-
-2
依题意模拟即可
#include<iostream> using namespace std; int money,cost,mama,flag=1,monthofdeath; //money代表在津津手里的钱,cost代表花费的钱,mama代表在妈妈手里的100元的张数,flag=1代表尚未透支,monthofdeath代表死亡月份 int main (){ for(int i=1;i<=12;i++){ money+=300; //每个月津津手里的钱都会增加300 cin>>cost; //输入这个月的花销 money-=cost; // 津津手里的钱减去这个月的花销等于剩余的钱 if(money<0) //若剩余的钱小于0, { flag=0; //旗帜倒下,即已经透支 monthofdeath=i; //输出死亡月份 break; //终止循环 } mama+=money/100; //剩余的钱整除100即为在妈妈手里的100元的张数 money%=100; //用100去模剩余的钱即为月底幸存的钱 } if(flag==1) //若旗帜未倒下,即坚持到年底还没有透支 { money+=mama*120; //剩余的钱 cout<<money; } else { cout<<-monthofdeath; } return 0; }
- 1
信息
- ID
- 90
- 时间
- 1000ms
- 内存
- 125MiB
- 难度
- 1
- 标签
- 递交数
- 389
- 已通过
- 176
- 上传者